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', action: 'list',
params: { params: {
pageSize: 50, pageSize: 50,
filter: {}, filter: {
'name.$ne': 'root',
},
showAnonymous: true,
sort: ['createdAt'], sort: ['createdAt'],
appends: [], appends: [],
}, },

View File

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