mirror of
https://github.com/strapi/strapi.git
synced 2025-09-28 18:01:26 +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 { hasPermissions, useRBACProvider, useStrapiApp, useAppInfo } from '@strapi/helper-plugin';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
@ -19,12 +19,26 @@ const useSettingsMenu = () => {
|
|||||||
const { shouldUpdateStrapi } = useAppInfo();
|
const { shouldUpdateStrapi } = useAppInfo();
|
||||||
const { settings } = useStrapiApp();
|
const { settings } = useStrapiApp();
|
||||||
const permissions = useSelector(selectAdminPermissions);
|
const permissions = useSelector(selectAdminPermissions);
|
||||||
|
|
||||||
const { global: globalLinks, admin: adminLinks } = useEnterprise(
|
const { global: globalLinks, admin: adminLinks } = useEnterprise(
|
||||||
LINKS_CE,
|
LINKS_CE,
|
||||||
async () => (await import('../../../../ee/admin/hooks/useSettingsMenu/constants')).LINKS_EE,
|
async () => (await import('../../../../ee/admin/hooks/useSettingsMenu/constants')).LINKS_EE,
|
||||||
{
|
{
|
||||||
combine(ceLinks, eeLinks) {
|
combine(ceLinks, eeLinks) {
|
||||||
function addPermissions(link) {
|
return {
|
||||||
|
admin: [...eeLinks.admin, ...ceLinks.admin],
|
||||||
|
global: [...ceLinks.global, ...eeLinks.global],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
defaultValue: {
|
||||||
|
admin: [],
|
||||||
|
global: [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const addPermissions = useCallback(
|
||||||
|
(link) => {
|
||||||
if (!link.id) {
|
if (!link.id) {
|
||||||
throw new Error('The settings menu item must have an id attribute.');
|
throw new Error('The settings menu item must have an id attribute.');
|
||||||
}
|
}
|
||||||
@ -33,18 +47,8 @@ const useSettingsMenu = () => {
|
|||||||
...link,
|
...link,
|
||||||
permissions: permissions.settings?.[link.id]?.main,
|
permissions: permissions.settings?.[link.id]?.main,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
admin: [...eeLinks.admin, ...ceLinks.admin].map(addPermissions),
|
|
||||||
global: [...ceLinks.global, ...eeLinks.global].map(addPermissions),
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
defaultValue: {
|
[permissions.settings]
|
||||||
admin: [],
|
|
||||||
global: [],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -86,26 +90,36 @@ const useSettingsMenu = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { global, ...otherSections } = settings;
|
const { global, ...otherSections } = settings;
|
||||||
|
|
||||||
const sections = formatLinks([
|
const sections = formatLinks([
|
||||||
{
|
{
|
||||||
...settings.global,
|
...settings.global,
|
||||||
links: sortLinks([...settings.global.links, ...globalLinks]).map((link) => ({
|
links: sortLinks([...settings.global.links, ...globalLinks.map(addPermissions)]).map(
|
||||||
|
(link) => ({
|
||||||
...link,
|
...link,
|
||||||
hasNotification: link.id === '000-application-infos' && shouldUpdateStrapi,
|
hasNotification: link.id === '000-application-infos' && shouldUpdateStrapi,
|
||||||
})),
|
})
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'permissions',
|
id: 'permissions',
|
||||||
intlLabel: { id: 'Settings.permissions', defaultMessage: 'Administration Panel' },
|
intlLabel: { id: 'Settings.permissions', defaultMessage: 'Administration Panel' },
|
||||||
links: adminLinks,
|
links: adminLinks.map(addPermissions),
|
||||||
},
|
},
|
||||||
...Object.values(otherSections),
|
...Object.values(otherSections),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
getData();
|
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;
|
export default useSettingsMenu;
|
||||||
|
@ -50,7 +50,8 @@ const SettingsNav = ({ menu }) => {
|
|||||||
<SubNavSections>
|
<SubNavSections>
|
||||||
{sections.map((section) => (
|
{sections.map((section) => (
|
||||||
<SubNavSection key={section.id} label={formatMessage(section.intlLabel)}>
|
<SubNavSection key={section.id} label={formatMessage(section.intlLabel)}>
|
||||||
{section.links.map((link) => (
|
{section.links.map((link) => {
|
||||||
|
return (
|
||||||
<SubNavLink
|
<SubNavLink
|
||||||
as={NavLink}
|
as={NavLink}
|
||||||
withBullet={link.hasNotification}
|
withBullet={link.hasNotification}
|
||||||
@ -60,7 +61,8 @@ const SettingsNav = ({ menu }) => {
|
|||||||
>
|
>
|
||||||
{formatMessage(link.intlLabel)}
|
{formatMessage(link.intlLabel)}
|
||||||
</SubNavLink>
|
</SubNavLink>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</SubNavSection>
|
</SubNavSection>
|
||||||
))}
|
))}
|
||||||
</SubNavSections>
|
</SubNavSections>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user