From 2784ec91b9a81ddfec2b4dd6e1b04477b2ef9187 Mon Sep 17 00:00:00 2001 From: Quentin BEY Date: Thu, 30 Jan 2025 15:59:58 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F(teams)=20hide=20displ?= =?UTF-8?q?ay=20add=20button=20when=20disallowed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The frontend should not display "add team" actions when the user has not the ability. --- .../teams-panel/__tests__/PanelTeams.test.tsx | 14 ++++++++++ .../teams-panel/components/PanelActions.tsx | 28 +++++++++++-------- .../teams/teams-panel/components/TeamList.tsx | 16 +++++++---- .../e2e/__tests__/app-desk/config.spec.ts | 13 +++++++-- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/frontend/apps/desk/src/features/teams/teams-panel/__tests__/PanelTeams.test.tsx b/src/frontend/apps/desk/src/features/teams/teams-panel/__tests__/PanelTeams.test.tsx index 68d355c37..5b74e058c 100644 --- a/src/frontend/apps/desk/src/features/teams/teams-panel/__tests__/PanelTeams.test.tsx +++ b/src/frontend/apps/desk/src/features/teams/teams-panel/__tests__/PanelTeams.test.tsx @@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import fetchMock from 'fetch-mock'; +import { useAuthStore } from '@/core/auth'; import { AppWrapper } from '@/tests/utils'; import { Panel } from '../components/Panel'; @@ -23,6 +24,19 @@ describe('PanelTeams', () => { }); it('renders with no team to display', async () => { + useAuthStore.setState({ + userData: { + id: '1', + email: 'test@example.com', + name: 'Test User', + abilities: { + teams: { can_view: true, can_create: true }, + mailboxes: { can_view: true }, + contacts: { can_view: true }, + }, + }, + }); + fetchMock.mock(`end:/teams/?ordering=-created_at`, []); render(, { wrapper: AppWrapper }); diff --git a/src/frontend/apps/desk/src/features/teams/teams-panel/components/PanelActions.tsx b/src/frontend/apps/desk/src/features/teams/teams-panel/components/PanelActions.tsx index 4c1cbe5fb..dea3ad267 100644 --- a/src/frontend/apps/desk/src/features/teams/teams-panel/components/PanelActions.tsx +++ b/src/frontend/apps/desk/src/features/teams/teams-panel/components/PanelActions.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'; import IconAdd from '@/assets/icons/icon-add.svg'; import IconSort from '@/assets/icons/icon-sort.svg'; import { Box, BoxButton, StyledLink } from '@/components'; +import { useAuthStore } from '@/core/auth'; import { useCunninghamTheme } from '@/cunningham'; import { TeamsOrdering } from '@/features/teams/team-management/api'; @@ -13,6 +14,9 @@ export const PanelActions = () => { const { t } = useTranslation(); const { changeOrdering, ordering } = useTeamStore(); const { colorsTokens } = useCunninghamTheme(); + const { userData } = useAuthStore(); + + const can_create = userData?.abilities?.teams.can_create ?? false; const isSortAsc = ordering === TeamsOrdering.BY_CREATED_ON; @@ -43,17 +47,19 @@ export const PanelActions = () => { >