added login / logout functionality and authorization rules via bouncer
This commit is contained in:
@@ -7,10 +7,8 @@ import Database from '@ioc:Adonis/Lucid/Database'
|
||||
|
||||
// TODO: #1 Implement paginator for Employee-Index
|
||||
export default class EmployeesController {
|
||||
public async index ({}: HttpContextContract) {
|
||||
const report = Database.manager.report()
|
||||
|
||||
console.log(report)
|
||||
public async index ({bouncer}: HttpContextContract) {
|
||||
await bouncer.authorize('employees.index')
|
||||
|
||||
return await Database.from('employees').select('*')
|
||||
}
|
||||
@@ -35,8 +33,14 @@ export default class EmployeesController {
|
||||
|
||||
}
|
||||
|
||||
public async show ({params}: HttpContextContract) {
|
||||
return await Employee.find(params.id)
|
||||
public async show ({params, bouncer}: HttpContextContract) {
|
||||
const emp = await Employee.findOrFail(params.id)
|
||||
|
||||
if (await bouncer.denies('employees.show', emp)){
|
||||
return 'Not admin or wrong user'
|
||||
}
|
||||
|
||||
return emp
|
||||
}
|
||||
|
||||
public async update ({params, request}: HttpContextContract) {
|
||||
|
||||
Reference in New Issue
Block a user