Skip to content

Commit

Permalink
fix(acl-plugin-setting): pluginPermissions for snippets check (nocoba…
Browse files Browse the repository at this point in the history
…se#3622)

* refactor:  pluginPermissions for snippets check

* fix: bug

* fix: bug
  • Loading branch information
katherinehhh committed Mar 6, 2024
1 parent d562687 commit bcb4456
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,6 +39,15 @@ export const PluginPermissions: React.FC<{
const settings = app.pluginSettingsManager.getList(false);
const allAclSnippets = app.pluginSettingsManager.getAclSnippets();
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(
() => snippets.includes('pm.*') && snippets.every((item) => !item.startsWith('!pm.')),
[snippets],
Expand All @@ -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.'));
}) || [],
);
},
},
);
Expand Down

0 comments on commit bcb4456

Please sign in to comment.