Solved #1 and ordering in EmployeesController, added some authentication
This commit is contained in:
@@ -34,11 +34,34 @@ import Employee from 'App/Models/Employee'
|
||||
export const { actions } = Bouncer
|
||||
|
||||
.define('employees.index', (user: User) => {
|
||||
return user.role === 'admin'
|
||||
if(user.role !== 'admin') return Bouncer.deny('You are not allowed to view all employees')
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.show', (user: User, employee : Employee) => {
|
||||
return user.role === 'admin' || user.id === employee.userId
|
||||
if(user.role !== 'admin' && user.id !== employee.userId){
|
||||
return Bouncer.deny('You are not allowd to view employees other than yourself')
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.store', (user: User) => {
|
||||
if(user.role !== 'admin') return Bouncer.deny('You are not allowd to create any employees')
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.destroy', (user: User) => {
|
||||
if(user.role !== 'admin') return Bouncer.deny('You are not allowed to delete any employees')
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.update', (user: User, editContractHours : boolean, employee: Employee) => {
|
||||
if(user.id !== employee.userId && user.role !== 'admin'){
|
||||
return Bouncer.deny('You are not allowed to edit employees other than yourself.')
|
||||
} else if (editContractHours && user.role !== 'admin'){
|
||||
return Bouncer.deny('You are not allowed to edit your contract hours.')
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user