Included user-information in employee Model.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
import Bouncer from '@ioc:Adonis/Addons/Bouncer'
|
||||
import User from 'App/Models/User'
|
||||
import Employee from 'App/Models/Employee'
|
||||
|
||||
/*
|
||||
@@ -33,30 +32,30 @@ import Employee from 'App/Models/Employee'
|
||||
*/
|
||||
export const { actions } = Bouncer
|
||||
|
||||
.define('employees.index', (user: User) => {
|
||||
.define('employees.index', (user: Employee) => {
|
||||
if(user.role !== 'admin') return Bouncer.deny('You are not allowed to view all employees')
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.show', (user: User, employee : Employee) => {
|
||||
if(user.role !== 'admin' && user.id !== employee.userId){
|
||||
.define('employees.show', (user: Employee, query: Employee) => {
|
||||
if(user.role !== 'admin' && user.id !== query.id){
|
||||
return Bouncer.deny('You are not allowd to view employees other than yourself')
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.store', (user: User) => {
|
||||
.define('employees.store', (user: Employee) => {
|
||||
if(user.role !== 'admin') return Bouncer.deny('You are not allowd to create any employees')
|
||||
return true
|
||||
})
|
||||
|
||||
.define('employees.destroy', (user: User) => {
|
||||
.define('employees.destroy', (user: Employee) => {
|
||||
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'){
|
||||
.define('employees.update', (user: Employee, editContractHours : boolean, query: Employee) => {
|
||||
if(user.id !== query.id && 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.')
|
||||
|
||||
Reference in New Issue
Block a user