fix: root & anonymous roles

This commit is contained in:
chenos 2022-04-13 12:18:44 +08:00
parent 9526ce13f2
commit b1decb359b
2 changed files with 14 additions and 8 deletions

View File

@ -57,7 +57,10 @@ export const roleSchema: ISchema = {
action: 'list',
params: {
pageSize: 50,
filter: {},
filter: {
'name.$ne': 'root',
},
showAnonymous: true,
sort: ['createdAt'],
appends: [],
},

View File

@ -304,16 +304,19 @@ export class PluginACL extends Plugin {
this.app.acl.skip('*', '*', (ctx) => {
return ctx.state.currentRole === 'root';
});
// root role
this.app.resourcer.use(async (ctx, next) => {
const { actionName, resourceName } = ctx.action.params;
const { actionName, resourceName, params } = ctx.action;
const { showAnonymous } = params || {};
if (actionName === 'list' && resourceName === 'roles') {
if (!showAnonymous) {
ctx.action.mergeParams({
filter: {
'name.$ne': 'root',
'name.$ne': 'anonymous',
},
});
}
}
await next();
});