[permissions] Filter tabs + registered actions according to permissions (#12657)

Note and task tabs in side panel should only show if user has reading
permission on them.

"Go to companies", "Go to workflows", etc. in command menu should only
show is user has reading permission on related objects.

<img width="507" alt="Capture d’écran 2025-06-17 à 11 09 50"
src="https://github.com/user-attachments/assets/3a2a4c25-0b9b-4ee6-b18f-b019b8a56d47"
/>
<img width="505" alt="Capture d’écran 2025-06-17 à 11 09 56"
src="https://github.com/user-attachments/assets/8a219955-cc8e-4dbf-a4f9-a50e1aaa4b59"
/>

**How to test** 
Assign a user with a custom role that has **no** read permissions on
notes/tasks/workflows/companies/opportunities/people (no need to test
them all but at least one between note and tasks; workflows; one between
companies/opportunities/people). Check that you don't see the related
tab / action.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Marie
2025-06-18 17:12:58 +02:00
committed by GitHub
parent e77e7e3149
commit da5ae34109
12 changed files with 206 additions and 35 deletions

View File

@ -10,11 +10,14 @@ import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import {
mockCurrentWorkspace,
mockedLimitedPermissionsUserData,
mockedUserData,
mockedWorkspaceMemberData,
} from '~/testing/mock-data/users';
import { sleep } from '~/utils/sleep';
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext';
import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
import { CommandMenuRouter } from '@/command-menu/components/CommandMenuRouter';
import { COMMAND_MENU_COMPONENT_INSTANCE_ID } from '@/command-menu/constants/CommandMenuComponentInstanceId';
import { commandMenuNavigationStackState } from '@/command-menu/states/commandMenuNavigationStackState';
@ -72,6 +75,9 @@ const meta: Meta<typeof CommandMenu> = {
I18nFrontDecorator,
(Story) => {
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
const setCurrentUserWorkspace = useSetRecoilState(
currentUserWorkspaceState,
);
const setCurrentWorkspaceMember = useSetRecoilState(
currentWorkspaceMemberState,
);
@ -84,6 +90,8 @@ const meta: Meta<typeof CommandMenu> = {
setCurrentWorkspace(mockCurrentWorkspace);
setCurrentWorkspaceMember(mockedWorkspaceMemberData);
setCurrentUserWorkspace(mockedUserData.currentUserWorkspace);
setIsCommandMenuOpened(true);
setCommandMenuNavigationStack([
{
@ -122,6 +130,29 @@ export const DefaultWithoutSearch: Story = {
},
};
export const LimitedPermissions: Story = {
play: async () => {
const canvas = within(document.body);
await expect(canvas.findByText('Go to Opportunities')).rejects.toThrow();
await expect(canvas.findByText('Go to Tasks')).rejects.toThrow();
expect(await canvas.findByText('Go to People')).toBeVisible();
expect(await canvas.findByText('Go to Settings')).toBeVisible();
expect(await canvas.findByText('Go to Notes')).toBeVisible();
},
decorators: [
(Story) => {
const setCurrentUserWorkspace = useSetRecoilState(
currentUserWorkspaceState,
);
setCurrentUserWorkspace(
mockedLimitedPermissionsUserData.currentUserWorkspace,
);
return <Story />;
},
],
};
export const MatchingNavigate: Story = {
play: async () => {
const canvas = within(document.body);