fix(acl-plugin-setting): pluginPermissions for snippets check (#3622)

* refactor:  pluginPermissions for snippets check

* fix: bug

* fix: bug
This commit is contained in:
katherinehhh 2024-03-06 14:11:08 +08:00 committed by GitHub
parent d56268730b
commit bcb445644c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ import { useAPIClient, useApp, useCompile, useCollectionRecord, useRequest } fro
import { Checkbox, message, Table } from 'antd'; import { Checkbox, message, Table } from 'antd';
import React, { useContext, useMemo, useState } from 'react'; import React, { useContext, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { flatMap } from 'lodash';
import { useStyles } from './style'; import { useStyles } from './style';
import { RolesManagerContext } from '../RolesManagerProvider'; import { RolesManagerContext } from '../RolesManagerProvider';
import lodash from 'lodash'; import lodash from 'lodash';
@ -38,6 +39,15 @@ export const PluginPermissions: React.FC<{
const settings = app.pluginSettingsManager.getList(false); const settings = app.pluginSettingsManager.getList(false);
const allAclSnippets = app.pluginSettingsManager.getAclSnippets(); const allAclSnippets = app.pluginSettingsManager.getAclSnippets();
const [snippets, setSnippets] = useState<string[]>([]); const [snippets, setSnippets] = useState<string[]>([]);
const flatPlugins = useMemo(() => {
return flatMap(settings, (item) => {
if (item.children) {
return [item, ...item.children];
} else {
return item;
}
});
}, [settings]);
const allChecked = useMemo( const allChecked = useMemo(
() => snippets.includes('pm.*') && snippets.every((item) => !item.startsWith('!pm.')), () => snippets.includes('pm.*') && snippets.every((item) => !item.startsWith('!pm.')),
[snippets], [snippets],
@ -57,7 +67,11 @@ export const PluginPermissions: React.FC<{
ready: !!role && active, ready: !!role && active,
refreshDeps: [role?.name], refreshDeps: [role?.name],
onSuccess(data) { onSuccess(data) {
setSnippets(data?.data || []); setSnippets(
data?.data.filter((v) => {
return flatPlugins.find((k) => v.includes(`!${k.aclSnippet}`) || !v.startsWith('!pm.'));
}) || [],
);
}, },
}, },
); );