Skip to content

Commit

Permalink
refactor(admin): replace oidc providers labels with variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelleBonnemay committed Dec 13, 2024
1 parent 0b25a5a commit a475e88
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 132 deletions.
26 changes: 7 additions & 19 deletions admin/app/components/users/user-detail-authentication-methods.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}

Expand All @@ -62,7 +50,7 @@ export default class UserDetailAuthenticationMethodsComponent extends Component
</section>

<ConfirmPopup
@message="Suppression de la méthode de connexion suivante : {{this.translatedType}}"
@message="Suppression de la méthode de connexion suivante : {{this.authenticationMethodName}}"
@title="Confirmer la suppression"
@submitTitle="Oui, je supprime"
@confirm={{this.removeAuthenticationMethod}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export default class AuthenticationMethod extends Component {
return userAuthenticationMethods.length > 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(
Expand Down Expand Up @@ -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</PixButton>
{{/if}}
{{#if this.isAllowedToAddEmailAuthenticationMethod}}
Expand Down Expand Up @@ -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</PixButton>
{{/if}}
{{/if}}
Expand Down Expand Up @@ -304,7 +313,7 @@ export default class AuthenticationMethod extends Component {
<PixButton
@size="small"
@variant="error"
@triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal "GAR"}}
@triggerAction={{fn @toggleDisplayRemoveAuthenticationMethodModal this.garAuthenticationMethod}}
>Supprimer</PixButton>
{{/if}}
{{#if this.hasGarAuthenticationMethod}}
Expand Down Expand Up @@ -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</PixButton>
{{/if}}
{{#if userOidcAuthenticationMethod.canBeReassignedToAnotherUser}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a475e88

Please sign in to comment.