From a475e880e5e9c6e3ef2b38fa2bb00c20b1994f7a Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Thu, 12 Dec 2024 21:47:26 +0100 Subject: [PATCH] refactor(admin): replace oidc providers labels with variables. --- .../user-detail-authentication-methods.gjs | 26 ++---- .../authentication-method.gjs | 20 ++-- .../users/get/authentication-methods.js | 17 ++-- .../users/authentication-method-test.js | 4 +- ...user-detail-authentication-methods-test.js | 91 ------------------- .../authentication-method-test.js | 4 +- 6 files changed, 30 insertions(+), 132 deletions(-) delete mode 100644 admin/tests/unit/components/users/user-detail-authentication-methods-test.js diff --git a/admin/app/components/users/user-detail-authentication-methods.gjs b/admin/app/components/users/user-detail-authentication-methods.gjs index 4140f09d287..bc65434f49a 100644 --- a/admin/app/components/users/user-detail-authentication-methods.gjs +++ b/admin/app/components/users/user-detail-authentication-methods.gjs @@ -7,30 +7,18 @@ import get from 'lodash/get'; import ConfirmPopup from '../confirm-popup'; import AuthenticationMethod from './user-detail-personal-information/authentication-method'; -const typesLabel = { - EMAIL: 'Adresse e-mail', - USERNAME: 'Identifiant', - POLE_EMPLOI: 'France Travail', - GAR: 'Médiacentre', - CNAV: 'CNAV', - FWB: 'Fédération Wallonie-Bruxelles', - PAYSDELALOIRE: 'Pays de la Loire', -}; - export default class UserDetailAuthenticationMethodsComponent extends Component { @tracked displayRemoveAuthenticationMethodModal = false; @tracked isLoading = false; @tracked authenticationMethodType = null; - + @tracked authenticationMethod = null; + @tracked authenticationMethodName = null; @service pixToast; - get translatedType() { - return typesLabel[this.authenticationMethodType]; - } - @action - toggleDisplayRemoveAuthenticationMethodModal(type) { - this.authenticationMethodType = type; + toggleDisplayRemoveAuthenticationMethodModal(authenticationMethod) { + this.authenticationMethodType = authenticationMethod.code; + this.authenticationMethodName = authenticationMethod.name; this.displayRemoveAuthenticationMethodModal = !this.displayRemoveAuthenticationMethodModal; } @@ -47,7 +35,7 @@ export default class UserDetailAuthenticationMethodsComponent extends Component this.pixToast.sendErrorNotification({ message: errorMessage }); } finally { this.isLoading = false; - this.toggleDisplayRemoveAuthenticationMethodModal(null); + this.displayRemoveAuthenticationMethodModal = false; } } @@ -62,7 +50,7 @@ export default class UserDetailAuthenticationMethodsComponent extends Component 1 || (userAuthenticationMethods.length === 1 && hasUsername && hasEmail); } + get emailAuthenticationMethod() { + return { code: 'EMAIL', name: 'Adresse e-mail' }; + } + get userNameAuthenticationMethod() { + return { code: 'USERNAME', name: 'Identifiant' }; + } + get garAuthenticationMethod() { + return { code: 'GAR', name: 'Médiacentre' }; + } get userOidcAuthenticationMethods() { return this.oidcIdentityProviders.list.map((oidcIdentityProvider) => { const userHasThisOidcAuthenticationMethod = this.authenticationMethods.any( @@ -237,7 +246,7 @@ export default class AuthenticationMethod extends Component { class="user-authentication-method__remove-button" @size="small" @variant="error" - @triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal "EMAIL"}} + @triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal this.emailAuthenticationMethod}} >Supprimer {{/if}} {{#if this.isAllowedToAddEmailAuthenticationMethod}} @@ -273,7 +282,7 @@ export default class AuthenticationMethod extends Component { class="user-authentication-method__remove-button" @size="small" @variant="error" - @triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal "USERNAME"}} + @triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal this.userNameAuthenticationMethod}} >Supprimer {{/if}} {{/if}} @@ -304,7 +313,7 @@ export default class AuthenticationMethod extends Component { Supprimer {{/if}} {{#if this.hasGarAuthenticationMethod}} @@ -343,10 +352,7 @@ export default class AuthenticationMethod extends Component { class="user-authentication-method__remove-button" @size="small" @variant="error" - @triggerAction={{fn - @toggleDisplayRemoveAuthenticationMethodModal - userOidcAuthenticationMethod.code - }} + @triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal userOidcAuthenticationMethod}} >Supprimer {{/if}} {{#if userOidcAuthenticationMethod.canBeReassignedToAnotherUser}} diff --git a/admin/app/controllers/authenticated/users/get/authentication-methods.js b/admin/app/controllers/authenticated/users/get/authentication-methods.js index e82241c354b..75f15836b64 100644 --- a/admin/app/controllers/authenticated/users/get/authentication-methods.js +++ b/admin/app/controllers/authenticated/users/get/authentication-methods.js @@ -8,13 +8,6 @@ export default class UserAuthenticationMethodsController extends Controller { ERROR_MESSAGES = { DEFAULT: 'Une erreur est survenue.', - STATUS_422: { - POLE_EMPLOI: "L'utilisateur a déjà une méthode de connexion France Travail.", - GAR: "L'utilisateur a déjà une méthode de connexion Médiacentre.", - CNAV: "L'utilisateur a déjà une méthode de connexion CNAV.", - FWB: "L'utilisateur a déjà une méthode de connexion Fédération Wallonie-Bruxelles.", - PAYSDELALOIRE: "L'utilisateur a déjà une méthode de connexion Pays de la Loire.", - }, STATUS_400: 'Cette requête est impossible', STATUS_404: "Cet utilisateur n'existe pas.", }; @@ -47,18 +40,18 @@ export default class UserAuthenticationMethodsController extends Controller { }, }); this.pixToast.sendSuccessNotification({ - message: `La méthode de connexion a bien été déplacé vers l'utilisateur ${targetUserId}`, + message: `La méthode de connexion a bien été déplacée vers l'utilisateur ${targetUserId}`, }); this.pixToast.sendSuccessNotification({ message: `L'utilisateur n'a plus de méthode de connexion ${reassignedAuthenticationMethodLabel}`, }); } catch (errors) { authenticationMethod.rollbackAttributes(); - this._handleResponseError(errors, identityProvider); + this._handleResponseError(errors, reassignedAuthenticationMethodLabel); } } - _handleResponseError(errorResponse, identityProvider) { + _handleResponseError(errorResponse, authenticationMethodLabel) { const { errors } = errorResponse; if (errors) { @@ -71,7 +64,9 @@ export default class UserAuthenticationMethodsController extends Controller { this.pixToast.sendErrorNotification({ message: this.ERROR_MESSAGES.STATUS_404 }); break; case '422': - this.pixToast.sendErrorNotification({ message: this.ERROR_MESSAGES.STATUS_422[identityProvider] }); + this.pixToast.sendErrorNotification({ + message: `L'utilisateur a déjà une méthode de connexion ${authenticationMethodLabel}`, + }); break; default: this.pixToast.sendErrorNotification({ message: this.ERROR_MESSAGES.DEFAULT }); diff --git a/admin/tests/acceptance/authenticated/users/authentication-method-test.js b/admin/tests/acceptance/authenticated/users/authentication-method-test.js index 39e4abbe59d..bcaf04a0c22 100644 --- a/admin/tests/acceptance/authenticated/users/authentication-method-test.js +++ b/admin/tests/acceptance/authenticated/users/authentication-method-test.js @@ -92,7 +92,7 @@ module('Acceptance | authenticated/users | authentication-method', function (hoo await clickByName('Valider le déplacement'); // then - assert.dom(screen.getByText("La méthode de connexion a bien été déplacé vers l'utilisateur 1")).exists(); + assert.dom(screen.getByText("La méthode de connexion a bien été déplacée vers l'utilisateur 1")).exists(); assert.dom(screen.getByText("L'utilisateur n'a plus de méthode de connexion Médiacentre")).exists(); assert.dom(screen.getByLabelText("L'utilisateur n'a pas de méthode de connexion Médiacentre")).exists(); }); @@ -126,7 +126,7 @@ module('Acceptance | authenticated/users | authentication-method', function (hoo await click(screen.getByRole('button', { name: 'Valider le déplacement' })); // then - assert.dom(screen.getByText("La méthode de connexion a bien été déplacé vers l'utilisateur 1")).exists(); + assert.dom(screen.getByText("La méthode de connexion a bien été déplacée vers l'utilisateur 1")).exists(); assert.dom(screen.getByText("L'utilisateur n'a plus de méthode de connexion Partenaire OIDC")).exists(); assert.dom(screen.getByLabelText("L'utilisateur n'a pas de méthode de connexion Partenaire OIDC")).exists(); }); diff --git a/admin/tests/unit/components/users/user-detail-authentication-methods-test.js b/admin/tests/unit/components/users/user-detail-authentication-methods-test.js deleted file mode 100644 index c36ee68ea40..00000000000 --- a/admin/tests/unit/components/users/user-detail-authentication-methods-test.js +++ /dev/null @@ -1,91 +0,0 @@ -import { setupTest } from 'ember-qunit'; -import { module, test } from 'qunit'; -import sinon from 'sinon'; - -import createGlimmerComponent from '../../../helpers/create-glimmer-component'; - -module('Unit | Component | users | user-detail-personal-information', function (hooks) { - setupTest(hooks); - - let component; - - hooks.beforeEach(function () { - component = createGlimmerComponent('component:users/user-detail-authentication-methods'); - component.pixToast = { - sendSuccessNotification: sinon.stub(), - sendErrorNotification: sinon.stub(), - }; - }); - - module('#translatedType', function () { - module('when authentication method is GAR', function () { - test('it should display "Médiacentre"', function (assert) { - // given - component.authenticationMethodType = 'GAR'; - - // when & then - assert.strictEqual(component.translatedType, 'Médiacentre'); - }); - }); - - module('when authentication method is PIX with email', function () { - test('it should display "Adresse e-mail"', function (assert) { - // given - component.authenticationMethodType = 'EMAIL'; - - // when & then - assert.strictEqual(component.translatedType, 'Adresse e-mail'); - }); - }); - - module('when authentication method is PIX with username', function () { - test('it should display "Identifiant"', function (assert) { - // given - component.authenticationMethodType = 'USERNAME'; - - // when & then - assert.strictEqual(component.translatedType, 'Identifiant'); - }); - }); - - module('when authentication method is POLE EMPLOI', function () { - test('it should display "Pôle Emploi"', function (assert) { - // given - component.authenticationMethodType = 'POLE_EMPLOI'; - - // when & then - assert.strictEqual(component.translatedType, 'France Travail'); - }); - }); - - module('when authentication method is CNAV', function () { - test('it should display "CNAV"', function (assert) { - // given - component.authenticationMethodType = 'CNAV'; - - // when & then - assert.strictEqual(component.translatedType, 'CNAV'); - }); - }); - - module('when authentication method is FWB', function () { - test('it displays "Fédération Wallonie-Bruxelles"', function (assert) { - // given - component.authenticationMethodType = 'FWB'; - - // when & then - assert.strictEqual(component.translatedType, 'Fédération Wallonie-Bruxelles'); - }); - }); - - module('when authentication method is PAYSDELALOIRE', function () { - test('it displays "Pays de la Loire"', function (assert) { - // given - component.authenticationMethodType = 'PAYSDELALOIRE'; - - // when & then - assert.strictEqual(component.translatedType, 'Pays de la Loire'); - }); - }); - }); -}); diff --git a/admin/tests/unit/components/users/user-detail-personal-information/authentication-method-test.js b/admin/tests/unit/components/users/user-detail-personal-information/authentication-method-test.js index 39f3e428d66..a448947107a 100644 --- a/admin/tests/unit/components/users/user-detail-personal-information/authentication-method-test.js +++ b/admin/tests/unit/components/users/user-detail-personal-information/authentication-method-test.js @@ -23,8 +23,8 @@ module('Unit | Component | users | user-detail-personal-information/authenticati component.targetUserId = '12'; component.showReassignOidcAuthenticationMethodModal = true; const oidcAuthenticationMethod = { - code: 'CNAV', - name: 'CNAV', + code: 'OIDC_EXAMPLE_NET', + name: 'OIDC Example', userHasThisOidcAuthenticationMethod: true, canBeRemovedFromUserAuthenticationMethods: true, canBeReassignedToAnotherUser: true,