mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Merge pull request #17237 from noobCode-69/setting-permission
Fix settings menu permissions in CE
This commit is contained in:
commit
f1c4c09e50
@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
import { hasPermissions, useRBACProvider, useStrapiApp, useAppInfo } from '@strapi/helper-plugin';
|
||||
import { useSelector } from 'react-redux';
|
||||
@ -19,25 +19,15 @@ const useSettingsMenu = () => {
|
||||
const { shouldUpdateStrapi } = useAppInfo();
|
||||
const { settings } = useStrapiApp();
|
||||
const permissions = useSelector(selectAdminPermissions);
|
||||
|
||||
const { global: globalLinks, admin: adminLinks } = useEnterprise(
|
||||
LINKS_CE,
|
||||
async () => (await import('../../../../ee/admin/hooks/useSettingsMenu/constants')).LINKS_EE,
|
||||
{
|
||||
combine(ceLinks, eeLinks) {
|
||||
function addPermissions(link) {
|
||||
if (!link.id) {
|
||||
throw new Error('The settings menu item must have an id attribute.');
|
||||
}
|
||||
|
||||
return {
|
||||
...link,
|
||||
permissions: permissions.settings?.[link.id]?.main,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
admin: [...eeLinks.admin, ...ceLinks.admin].map(addPermissions),
|
||||
global: [...ceLinks.global, ...eeLinks.global].map(addPermissions),
|
||||
admin: [...eeLinks.admin, ...ceLinks.admin],
|
||||
global: [...ceLinks.global, ...eeLinks.global],
|
||||
};
|
||||
},
|
||||
defaultValue: {
|
||||
@ -47,6 +37,20 @@ const useSettingsMenu = () => {
|
||||
}
|
||||
);
|
||||
|
||||
const addPermissions = useCallback(
|
||||
(link) => {
|
||||
if (!link.id) {
|
||||
throw new Error('The settings menu item must have an id attribute.');
|
||||
}
|
||||
|
||||
return {
|
||||
...link,
|
||||
permissions: permissions.settings?.[link.id]?.main,
|
||||
};
|
||||
},
|
||||
[permissions.settings]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const getData = async () => {
|
||||
const buildMenuPermissions = (sections) =>
|
||||
@ -86,26 +90,36 @@ const useSettingsMenu = () => {
|
||||
};
|
||||
|
||||
const { global, ...otherSections } = settings;
|
||||
|
||||
const sections = formatLinks([
|
||||
{
|
||||
...settings.global,
|
||||
links: sortLinks([...settings.global.links, ...globalLinks]).map((link) => ({
|
||||
...link,
|
||||
hasNotification: link.id === '000-application-infos' && shouldUpdateStrapi,
|
||||
})),
|
||||
links: sortLinks([...settings.global.links, ...globalLinks.map(addPermissions)]).map(
|
||||
(link) => ({
|
||||
...link,
|
||||
hasNotification: link.id === '000-application-infos' && shouldUpdateStrapi,
|
||||
})
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'permissions',
|
||||
intlLabel: { id: 'Settings.permissions', defaultMessage: 'Administration Panel' },
|
||||
links: adminLinks,
|
||||
links: adminLinks.map(addPermissions),
|
||||
},
|
||||
...Object.values(otherSections),
|
||||
]);
|
||||
|
||||
getData();
|
||||
}, [adminLinks, globalLinks, userPermissions, settings, shouldUpdateStrapi]);
|
||||
}, [adminLinks, globalLinks, userPermissions, settings, shouldUpdateStrapi, addPermissions]);
|
||||
|
||||
return { isLoading, menu };
|
||||
const filterMenu = (menuItem) => {
|
||||
return {
|
||||
...menuItem,
|
||||
links: menuItem.links.filter((link) => link.isDisplayed),
|
||||
};
|
||||
};
|
||||
|
||||
return { isLoading, menu: menu.map(filterMenu) };
|
||||
};
|
||||
|
||||
export default useSettingsMenu;
|
||||
|
@ -50,17 +50,19 @@ const SettingsNav = ({ menu }) => {
|
||||
<SubNavSections>
|
||||
{sections.map((section) => (
|
||||
<SubNavSection key={section.id} label={formatMessage(section.intlLabel)}>
|
||||
{section.links.map((link) => (
|
||||
<SubNavLink
|
||||
as={NavLink}
|
||||
withBullet={link.hasNotification}
|
||||
to={link.to}
|
||||
onClick={() => handleClickOnLink(link.to)}
|
||||
key={link.id}
|
||||
>
|
||||
{formatMessage(link.intlLabel)}
|
||||
</SubNavLink>
|
||||
))}
|
||||
{section.links.map((link) => {
|
||||
return (
|
||||
<SubNavLink
|
||||
as={NavLink}
|
||||
withBullet={link.hasNotification}
|
||||
to={link.to}
|
||||
onClick={() => handleClickOnLink(link.to)}
|
||||
key={link.id}
|
||||
>
|
||||
{formatMessage(link.intlLabel)}
|
||||
</SubNavLink>
|
||||
);
|
||||
})}
|
||||
</SubNavSection>
|
||||
))}
|
||||
</SubNavSections>
|
||||
|
Loading…
x
Reference in New Issue
Block a user