fix: root & anonymous roles
This commit is contained in:
parent
9526ce13f2
commit
b1decb359b
@ -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: [],
|
||||||
},
|
},
|
||||||
|
@ -304,16 +304,19 @@ 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') {
|
||||||
|
if (!showAnonymous) {
|
||||||
ctx.action.mergeParams({
|
ctx.action.mergeParams({
|
||||||
filter: {
|
filter: {
|
||||||
'name.$ne': 'root',
|
'name.$ne': 'anonymous',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await next();
|
await next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user