Add initial project files
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { BasePolicy } from '@adonisjs/bouncer'
|
||||
import type { AuthorizerResponse } from '@adonisjs/bouncer/types'
|
||||
import Admins from '#base_modules/Admin/model/admin'
|
||||
import { getAdminPermissionSlugs } from '#services/permission_service'
|
||||
|
||||
export default class PermissionPolicy extends BasePolicy {
|
||||
async permissionList(user: Admins): Promise<AuthorizerResponse> {
|
||||
if (!user) return false
|
||||
const perms = await getAdminPermissionSlugs(user)
|
||||
return perms.has('permission.view')
|
||||
}
|
||||
|
||||
async viewPermission(user: Admins): Promise<AuthorizerResponse> {
|
||||
if (!user) return false
|
||||
const perms = await getAdminPermissionSlugs(user)
|
||||
return perms.has('permission.view')
|
||||
}
|
||||
|
||||
async createPermission(user: Admins): Promise<AuthorizerResponse> {
|
||||
if (!user) return false
|
||||
const perms = await getAdminPermissionSlugs(user)
|
||||
return perms.has('permission.create')
|
||||
}
|
||||
|
||||
async updatePermission(user: Admins): Promise<AuthorizerResponse> {
|
||||
if (!user) return false
|
||||
const perms = await getAdminPermissionSlugs(user)
|
||||
return perms.has('permission.update')
|
||||
}
|
||||
|
||||
async deletePermission(user: Admins): Promise<AuthorizerResponse> {
|
||||
if (!user) return false
|
||||
const perms = await getAdminPermissionSlugs(user)
|
||||
return perms.has('permission.delete')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user