mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-02-26 07:50:28 +00:00
角色权限过滤
This commit is contained in:
parent
c971260ee1
commit
e0fd305b28
@ -1,5 +1,6 @@
|
|||||||
import { Provide } from '@midwayjs/decorator';
|
import { Provide } from '@midwayjs/decorator';
|
||||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||||
|
import { Context } from 'vm';
|
||||||
import { AdminSysRoleEntity } from '../../entity/sys/role';
|
import { AdminSysRoleEntity } from '../../entity/sys/role';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,9 +12,13 @@ import { AdminSysRoleEntity } from '../../entity/sys/role';
|
|||||||
entity: AdminSysRoleEntity,
|
entity: AdminSysRoleEntity,
|
||||||
pageQueryOp: {
|
pageQueryOp: {
|
||||||
keyWordLikeFields: ['name', 'label'],
|
keyWordLikeFields: ['name', 'label'],
|
||||||
where: (async () => {
|
where: (async (ctx: Context) => {
|
||||||
|
const { userId, roleIds, role } = ctx.admin;
|
||||||
return [
|
return [
|
||||||
|
// 超级管理员的角色不展示
|
||||||
['label != :label', { label: 'admin' }],
|
['label != :label', { label: 'admin' }],
|
||||||
|
// 如果不是超管,只能看到自己新建的或者自己有的角色
|
||||||
|
['(userId=:userId or id in (:roleIds))', { userId, roleIds }, role != 'admin']
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user