From 74d5626b272f316d112088e075a59fdb42127dee Mon Sep 17 00:00:00 2001 From: Maxime GRANDCOLAS Date: Mon, 27 Jan 2025 15:17:55 +0100 Subject: [PATCH] [MS] Fixed error when trying to create a SaaS org with an incorrect account --- client/src/locales/en-US.json | 1 + client/src/locales/fr-FR.json | 1 + client/src/services/bms/api.ts | 14 +++++------ .../creation/CreateOrganizationSaas.vue | 9 +++++-- client/tests/e2e/helpers/bms.ts | 24 ++++++++++++------- .../specs/create_organization_saas.spec.ts | 14 +++++++++++ 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/client/src/locales/en-US.json b/client/src/locales/en-US.json index 73cd3869236..4cf00f6fdff 100644 --- a/client/src/locales/en-US.json +++ b/client/src/locales/en-US.json @@ -277,6 +277,7 @@ "alreadyExists": "This organization name is not available, please choose another one.", "generic": "Failed to create the organization (reason: {reason}).", "customOrderNotAuthorized": "Clients with a custom contract are not allowed to directly create organizations. If you need another organization, please make a request from your customer area.", + "notClientAccount": "Your account is not a client account.", "incompatibleServer": "Your version of Parsec is incompatible with the server. Please update the app or contact an administrator." }, "cancelConfirm": "Cancel organization creation", diff --git a/client/src/locales/fr-FR.json b/client/src/locales/fr-FR.json index 78a2493b517..d2c46e3b075 100644 --- a/client/src/locales/fr-FR.json +++ b/client/src/locales/fr-FR.json @@ -277,6 +277,7 @@ "alreadyExists": "Ce nom d'organisation n'est pas disponible, veuillez en choisir un autre.", "generic": "Impossible de créer l'organisation (raison: {reason}).", "customOrderNotAuthorized": "Les clients en contrat sur mesure ne sont pas autorisés à créer une organisation directement. Si vous avez besoin d'une organisation supplémentaire, veuillez remplir une demande depuis votre espace client.", + "notClientAccount": "Votre compte n'est pas un compte client.", "incompatibleServer": "Votre version de Parsec n'est pas compatible avec le serveur. Veuillez mettre à jour votre application ou contacter un administrateur." }, "cancelConfirm": "Annulation", diff --git a/client/src/services/bms/api.ts b/client/src/services/bms/api.ts index 720a637ed66..22b91a7a759 100644 --- a/client/src/services/bms/api.ts +++ b/client/src/services/bms/api.ts @@ -112,13 +112,13 @@ async function getPersonalInformation(token: AuthenticationToken): Promise { async function onLoginSuccess(_token: AuthenticationToken, info: PersonalInformationResultData): Promise { if ( - (info.billingSystem === BillingSystem.CustomOrder || info.billingSystem === BillingSystem.ExperimentalCandidate) && + (info.billingSystem === BillingSystem.CustomOrder || + info.billingSystem === BillingSystem.ExperimentalCandidate || + info.billingSystem === BillingSystem.None) && !props.bootstrapLink ) { emits('closeRequested', true); props.informationManager.present( new Information({ - message: 'CreateOrganization.errors.customOrderNotAuthorized', + message: + info.billingSystem === BillingSystem.None + ? 'CreateOrganization.errors.notClientAccount' + : 'CreateOrganization.errors.customOrderNotAuthorized', level: InformationLevel.Error, }), PresentationMode.Modal, diff --git a/client/tests/e2e/helpers/bms.ts b/client/tests/e2e/helpers/bms.ts index 9825fc1e9f7..48b2b34cc7c 100644 --- a/client/tests/e2e/helpers/bms.ts +++ b/client/tests/e2e/helpers/bms.ts @@ -100,26 +100,32 @@ async function mockLogin(page: Page, options?: MockRouteOptions): Promise interface MockUserOverload { billingSystem?: 'STRIPE' | 'CUSTOM_ORDER' | 'NONE' | 'EXPERIMENTAL_CANDIDATE'; + noClient?: boolean; } async function mockUserRoute(page: Page, overload: MockUserOverload = {}, options?: MockRouteOptions): Promise { await mockRoute(page, `**/users/${DEFAULT_USER_INFORMATION.id}`, options, async (route) => { if (route.request().method() === 'GET') { + let client = null; + if (!overload.noClient) { + client = { + firstname: UserData.firstName, + lastname: UserData.lastName, + id: '1337', + job: UserData.job, + company: UserData.company, + phone: UserData.phone, + billing_system: overload.billingSystem ?? 'STRIPE', + }; + } + await route.fulfill({ status: 200, json: { id: DEFAULT_USER_INFORMATION.id, created_at: '2024-07-15T13:21:32.141317Z', email: UserData.email, - client: { - firstname: UserData.firstName, - lastname: UserData.lastName, - id: '1337', - job: UserData.job, - company: UserData.company, - phone: UserData.phone, - billing_system: overload.billingSystem ?? 'STRIPE', - }, + client: client, }, }); } else if (route.request().method() === 'PATCH') { diff --git a/client/tests/e2e/specs/create_organization_saas.spec.ts b/client/tests/e2e/specs/create_organization_saas.spec.ts index 1d01497f0c8..d4b14a02677 100644 --- a/client/tests/e2e/specs/create_organization_saas.spec.ts +++ b/client/tests/e2e/specs/create_organization_saas.spec.ts @@ -448,3 +448,17 @@ msTest('Try to create an org with custom order', async ({ home }) => { 'Error', ); }); + +msTest('Try to create an org without being a client', async ({ home }) => { + const modal = await openCreateOrganizationModal(home); + + await MockBms.mockLogin(home); + await MockBms.mockUserRoute(home, { noClient: true }); + + const bmsContainer = modal.locator('.saas-login'); + await fillIonInput(bmsContainer.locator('ion-input').nth(0), DEFAULT_USER_INFORMATION.email); + await fillIonInput(bmsContainer.locator('ion-input').nth(1), DEFAULT_USER_INFORMATION.password); + await bmsContainer.locator('.saas-login-button').locator('.saas-login-button__item').nth(1).click(); + await expect(modal).toBeHidden(); + await expect(home).toShowInformationModal('Your account is not a client account.', 'Error'); +});