From bcb445644c6531d9492fbb78b8683a422ff62c3c Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Wed, 6 Mar 2024 14:11:08 +0800 Subject: [PATCH] fix(acl-plugin-setting): pluginPermissions for snippets check (#3622) * refactor: pluginPermissions for snippets check * fix: bug * fix: bug --- .../src/client/permissions/PluginPermissions.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@nocobase/plugin-acl/src/client/permissions/PluginPermissions.tsx b/packages/plugins/@nocobase/plugin-acl/src/client/permissions/PluginPermissions.tsx index eb32f9ab7..301d61bdb 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/client/permissions/PluginPermissions.tsx +++ b/packages/plugins/@nocobase/plugin-acl/src/client/permissions/PluginPermissions.tsx @@ -2,6 +2,7 @@ import { useAPIClient, useApp, useCompile, useCollectionRecord, useRequest } fro import { Checkbox, message, Table } from 'antd'; import React, { useContext, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { flatMap } from 'lodash'; import { useStyles } from './style'; import { RolesManagerContext } from '../RolesManagerProvider'; import lodash from 'lodash'; @@ -38,6 +39,15 @@ export const PluginPermissions: React.FC<{ const settings = app.pluginSettingsManager.getList(false); const allAclSnippets = app.pluginSettingsManager.getAclSnippets(); const [snippets, setSnippets] = useState([]); + const flatPlugins = useMemo(() => { + return flatMap(settings, (item) => { + if (item.children) { + return [item, ...item.children]; + } else { + return item; + } + }); + }, [settings]); const allChecked = useMemo( () => snippets.includes('pm.*') && snippets.every((item) => !item.startsWith('!pm.')), [snippets], @@ -57,7 +67,11 @@ export const PluginPermissions: React.FC<{ ready: !!role && active, refreshDeps: [role?.name], onSuccess(data) { - setSnippets(data?.data || []); + setSnippets( + data?.data.filter((v) => { + return flatPlugins.find((k) => v.includes(`!${k.aclSnippet}`) || !v.startsWith('!pm.')); + }) || [], + ); }, }, );