✨(frontend) restrict mailbox creation
- update mailbox creation feature by introducing the use of new mail domain ability field to hide or show mailbox creation button - update related e2e tests
This commit is contained in:
committed by
Sebastien Nobour
parent
14deca13f4
commit
45dbdd6c4c
@@ -91,6 +91,7 @@ export function MailDomainsContent({ mailDomain }: { mailDomain: MailDomain }) {
|
||||
<TopBanner
|
||||
name={mailDomain.name}
|
||||
setIsFormVisible={setIsCreateMailboxFormVisible}
|
||||
abilities={mailDomain.abilities}
|
||||
/>
|
||||
<Card
|
||||
$padding={{ bottom: 'small' }}
|
||||
@@ -127,9 +128,11 @@ export function MailDomainsContent({ mailDomain }: { mailDomain: MailDomain }) {
|
||||
const TopBanner = ({
|
||||
name,
|
||||
setIsFormVisible,
|
||||
abilities,
|
||||
}: {
|
||||
name: string;
|
||||
setIsFormVisible: (value: boolean) => void;
|
||||
abilities: MailDomain['abilities'];
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -147,12 +150,14 @@ const TopBanner = ({
|
||||
</Text>
|
||||
</Box>
|
||||
<Box $margin={{ all: 'big', bottom: 'small' }} $align="flex-end">
|
||||
<Button
|
||||
aria-label={t(`Create a mailbox in {{name}} domain`, { name })}
|
||||
onClick={() => setIsFormVisible(true)}
|
||||
>
|
||||
{t('Create a mailbox')}
|
||||
</Button>
|
||||
{abilities.post ? (
|
||||
<Button
|
||||
aria-label={t(`Create a mailbox in {{name}} domain`, { name })}
|
||||
onClick={() => setIsFormVisible(true)}
|
||||
>
|
||||
{t('Create a mailbox')}
|
||||
</Button>
|
||||
) : null}
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -6,6 +6,14 @@ export interface MailDomain {
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
slug: string;
|
||||
abilities: {
|
||||
get: boolean;
|
||||
patch: boolean;
|
||||
put: boolean;
|
||||
post: boolean;
|
||||
delete: boolean;
|
||||
manage_accesses: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MailDomainMailbox {
|
||||
|
||||
@@ -15,6 +15,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'domainfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mails.fr',
|
||||
@@ -22,6 +30,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'mailsfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'versailles.net',
|
||||
@@ -29,6 +45,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'versaillesnet',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'paris.fr',
|
||||
@@ -36,6 +60,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'parisfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -99,8 +131,7 @@ test.describe('Mail domain create mailbox', () => {
|
||||
await keyCloakSignIn(page, browserName);
|
||||
});
|
||||
|
||||
// user should have administrator or owner role on this domain to be able perform this action
|
||||
test('checks user can create a mailbox for a mail domain', async ({
|
||||
test('checks user can create a mailbox when he has post ability', async ({
|
||||
page,
|
||||
}) => {
|
||||
const newMailbox = {
|
||||
@@ -224,6 +255,62 @@ test.describe('Mail domain create mailbox', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('checks user is not allowed to create a mailbox when he is missing post ability', async ({
|
||||
page,
|
||||
}) => {
|
||||
const localMailDomainsFixtures = [...mailDomainsFixtures];
|
||||
localMailDomainsFixtures[0].abilities.post = false;
|
||||
const localMailDomainDomainFr = localMailDomainsFixtures[0];
|
||||
const localMailboxFixtures = { ...mailboxesFixtures };
|
||||
|
||||
const interceptRequests = (page: Page) => {
|
||||
void page.route('**/api/v1.0/mail-domains/?page=*', (route) => {
|
||||
void route.fulfill({
|
||||
json: {
|
||||
count: localMailDomainsFixtures.length,
|
||||
next: null,
|
||||
previous: null,
|
||||
results: localMailDomainsFixtures,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
void page.route('**/api/v1.0/mail-domains/domainfr', (route) => {
|
||||
void route.fulfill({
|
||||
json: localMailDomainDomainFr,
|
||||
});
|
||||
});
|
||||
|
||||
void page.route(
|
||||
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1**',
|
||||
(route) => {
|
||||
void route.fulfill({
|
||||
json: {
|
||||
count: localMailboxFixtures.domainFr.page1.length,
|
||||
next: null,
|
||||
previous: null,
|
||||
results: localMailboxFixtures.domainFr.page1,
|
||||
},
|
||||
});
|
||||
},
|
||||
{ times: 1 },
|
||||
);
|
||||
};
|
||||
|
||||
void interceptRequests(page);
|
||||
|
||||
await page
|
||||
.locator('menu')
|
||||
.first()
|
||||
.getByLabel(`Mail Domains button`)
|
||||
.click();
|
||||
await page.getByRole('listbox').first().getByText('domain.fr').click();
|
||||
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Create a mailbox' }),
|
||||
).not.toBeInViewport();
|
||||
});
|
||||
|
||||
test('checks client invalidation messages are displayed and no mailbox creation request is sent when fields are not properly filled', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
@@ -12,6 +12,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'domainfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mails.fr',
|
||||
@@ -19,6 +27,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'mailsfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'versailles.net',
|
||||
@@ -26,6 +42,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'versaillesnet',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'paris.fr',
|
||||
@@ -33,6 +57,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'parisfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -11,6 +11,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'domainfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mails.fr',
|
||||
@@ -18,6 +26,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'mailsfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'versailles.net',
|
||||
@@ -25,6 +41,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'versaillesnet',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'paris.fr',
|
||||
@@ -32,6 +56,14 @@ const mailDomainsFixtures: MailDomain[] = [
|
||||
created_at: currentDateIso,
|
||||
updated_at: currentDateIso,
|
||||
slug: 'parisfr',
|
||||
abilities: {
|
||||
get: true,
|
||||
patch: true,
|
||||
put: true,
|
||||
post: true,
|
||||
delete: true,
|
||||
manage_accesses: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user