🚑️(teams) hide display add button when disallowed
The frontend should not display "add team" actions when the user has not the ability.
This commit is contained in:
@@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react';
|
|||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import fetchMock from 'fetch-mock';
|
import fetchMock from 'fetch-mock';
|
||||||
|
|
||||||
|
import { useAuthStore } from '@/core/auth';
|
||||||
import { AppWrapper } from '@/tests/utils';
|
import { AppWrapper } from '@/tests/utils';
|
||||||
|
|
||||||
import { Panel } from '../components/Panel';
|
import { Panel } from '../components/Panel';
|
||||||
@@ -23,6 +24,19 @@ describe('PanelTeams', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('renders with no team to display', async () => {
|
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`, []);
|
fetchMock.mock(`end:/teams/?ordering=-created_at`, []);
|
||||||
|
|
||||||
render(<TeamList />, { wrapper: AppWrapper });
|
render(<TeamList />, { wrapper: AppWrapper });
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import IconAdd from '@/assets/icons/icon-add.svg';
|
import IconAdd from '@/assets/icons/icon-add.svg';
|
||||||
import IconSort from '@/assets/icons/icon-sort.svg';
|
import IconSort from '@/assets/icons/icon-sort.svg';
|
||||||
import { Box, BoxButton, StyledLink } from '@/components';
|
import { Box, BoxButton, StyledLink } from '@/components';
|
||||||
|
import { useAuthStore } from '@/core/auth';
|
||||||
import { useCunninghamTheme } from '@/cunningham';
|
import { useCunninghamTheme } from '@/cunningham';
|
||||||
import { TeamsOrdering } from '@/features/teams/team-management/api';
|
import { TeamsOrdering } from '@/features/teams/team-management/api';
|
||||||
|
|
||||||
@@ -13,6 +14,9 @@ export const PanelActions = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { changeOrdering, ordering } = useTeamStore();
|
const { changeOrdering, ordering } = useTeamStore();
|
||||||
const { colorsTokens } = useCunninghamTheme();
|
const { colorsTokens } = useCunninghamTheme();
|
||||||
|
const { userData } = useAuthStore();
|
||||||
|
|
||||||
|
const can_create = userData?.abilities?.teams.can_create ?? false;
|
||||||
|
|
||||||
const isSortAsc = ordering === TeamsOrdering.BY_CREATED_ON;
|
const isSortAsc = ordering === TeamsOrdering.BY_CREATED_ON;
|
||||||
|
|
||||||
@@ -43,17 +47,19 @@ export const PanelActions = () => {
|
|||||||
>
|
>
|
||||||
<IconSort width={30} height={30} aria-hidden="true" />
|
<IconSort width={30} height={30} aria-hidden="true" />
|
||||||
</BoxButton>
|
</BoxButton>
|
||||||
<StyledLink href="/teams/create">
|
{can_create && (
|
||||||
<BoxButton
|
<StyledLink href="/teams/create">
|
||||||
as="span"
|
<BoxButton
|
||||||
$margin={{ all: 'auto' }}
|
as="span"
|
||||||
aria-label={t('Add a team')}
|
$margin={{ all: 'auto' }}
|
||||||
$color={colorsTokens()['primary-600']}
|
aria-label={t('Add a team')}
|
||||||
tabIndex={-1}
|
$color={colorsTokens()['primary-600']}
|
||||||
>
|
tabIndex={-1}
|
||||||
<IconAdd width={27} height={27} aria-hidden="true" />
|
>
|
||||||
</BoxButton>
|
<IconAdd width={27} height={27} aria-hidden="true" />
|
||||||
</StyledLink>
|
</BoxButton>
|
||||||
|
</StyledLink>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import React, { useRef } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Box, Text } from '@/components';
|
import { Box, Text } from '@/components';
|
||||||
|
import { useAuthStore } from '@/core/auth';
|
||||||
import { Team, useTeams } from '@/features/teams/team-management';
|
import { Team, useTeams } from '@/features/teams/team-management';
|
||||||
|
|
||||||
import { useTeamStore } from '../store';
|
import { useTeamStore } from '../store';
|
||||||
@@ -17,6 +18,9 @@ interface PanelTeamsStateProps {
|
|||||||
|
|
||||||
const TeamListState = ({ isLoading, isError, teams }: PanelTeamsStateProps) => {
|
const TeamListState = ({ isLoading, isError, teams }: PanelTeamsStateProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { userData } = useAuthStore();
|
||||||
|
|
||||||
|
const can_create = userData?.abilities?.teams.can_create ?? false;
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
return (
|
return (
|
||||||
@@ -42,11 +46,13 @@ const TeamListState = ({ isLoading, isError, teams }: PanelTeamsStateProps) => {
|
|||||||
<Text as="p" $margin={{ vertical: 'none' }}>
|
<Text as="p" $margin={{ vertical: 'none' }}>
|
||||||
{t('0 group to display.')}
|
{t('0 group to display.')}
|
||||||
</Text>
|
</Text>
|
||||||
<Text as="p">
|
{can_create && (
|
||||||
{t(
|
<Text as="p">
|
||||||
'Create your first team by clicking on the "Create a new team" button.',
|
{t(
|
||||||
)}
|
'Create your first team by clicking on the "Create a new team" button.',
|
||||||
</Text>
|
)}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,18 @@ test.describe('Config', () => {
|
|||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
await keyCloakSignIn(page, browserName, 'mail-member');
|
await keyCloakSignIn(page, browserName, 'mail-member');
|
||||||
|
|
||||||
await expect(page.locator('menu')).toBeHidden();
|
await page
|
||||||
|
.locator('menu')
|
||||||
|
.first()
|
||||||
|
.getByLabel(`Mail Domains button`)
|
||||||
|
.click();
|
||||||
|
await expect(page).toHaveURL(/mail-domains\//);
|
||||||
|
|
||||||
await expect(page.getByText('Mail Domains')).toBeVisible();
|
await expect(
|
||||||
|
page
|
||||||
|
.getByLabel('Mail domains panel', { exact: true })
|
||||||
|
.getByText('Mail Domains'),
|
||||||
|
).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it checks that the user abilities display teams', async ({
|
test('it checks that the user abilities display teams', async ({
|
||||||
|
|||||||
Reference in New Issue
Block a user