From b1decb359bc8d46a610ee5602ed4b97aeb8dbaad Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 13 Apr 2022 12:18:44 +0800 Subject: [PATCH] fix: root & anonymous roles --- .../src/acl/Configuration/schemas/roles.ts | 5 ++++- packages/plugin-acl/src/server.ts | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/client/src/acl/Configuration/schemas/roles.ts b/packages/client/src/acl/Configuration/schemas/roles.ts index 17b3ed1d2..ba4ffd2e1 100644 --- a/packages/client/src/acl/Configuration/schemas/roles.ts +++ b/packages/client/src/acl/Configuration/schemas/roles.ts @@ -57,7 +57,10 @@ export const roleSchema: ISchema = { action: 'list', params: { pageSize: 50, - filter: {}, + filter: { + 'name.$ne': 'root', + }, + showAnonymous: true, sort: ['createdAt'], appends: [], }, diff --git a/packages/plugin-acl/src/server.ts b/packages/plugin-acl/src/server.ts index 9fbcf8103..b5d744313 100644 --- a/packages/plugin-acl/src/server.ts +++ b/packages/plugin-acl/src/server.ts @@ -304,15 +304,18 @@ 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') { - ctx.action.mergeParams({ - filter: { - 'name.$ne': 'root', - }, - }); + if (!showAnonymous) { + ctx.action.mergeParams({ + filter: { + 'name.$ne': 'anonymous', + }, + }); + } } await next(); });