Skip to content

Commit

Permalink
feat(admin): add active authentication methods count
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelleBonnemay committed Jan 2, 2025
1 parent 4a8c7c3 commit d6a6309
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions admin/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ export default class User extends Model {
get participationsCount() {
return this.participations.length;
}
get loginOptionsCount() {
console.log(this.authenticationMethods.length);
const result =
this.username && this.email ? this.authenticationMethods.length + 1 : this.authenticationMethods.length;
console.log(result);
return result;
}
}
1 change: 1 addition & 0 deletions admin/app/templates/authenticated/users/get.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<LinkTo @route="authenticated.users.get.authentication-methods" @model={{@model}} class="navbar-item">
{{t "pages.user-details.navbar.authentication-methods"}}
({{@model.loginOptionsCount}})
</LinkTo>

<LinkTo @route="authenticated.users.get.profile" @model={{@model}} class="navbar-item">
Expand Down
26 changes: 21 additions & 5 deletions admin/tests/acceptance/authenticated/users/get-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ module('Acceptance | authenticated/users/get', function (hooks) {
test('displays user detail information page', async function (assert) {
// given
this.intl = this.owner.lookup('service:intl');
const user = await _buildAndAuthenticateUser(this.server, { email: 'john.harry@example.net', username: null });
const user = await _buildAndAuthenticateUser(this.server, {
email: 'john.harry@example.net',
username: 'john.harry0101',
});
const expectedOrganizationMembershipsCount = 2;
const expectedParticipationCount = 1;
const expectedCertificationCenterCount = 3;
const expectedLoginOptionsCount = 3;

// when
const screen = await visit(`/users/${user.id}`);
Expand All @@ -37,7 +41,9 @@ module('Acceptance | authenticated/users/get', function (hooks) {

const userNavigation = within(screen.getByLabelText("Navigation de la section détails d'un utilisateur"));
assert.dom(userNavigation.getByRole('link', { name: 'Informations prescrit' })).exists();
assert.dom(userNavigation.getByRole('link', { name: 'Méthodes de connexion' })).exists();
assert
.dom(userNavigation.getByRole('link', { name: `Méthodes de connexion (${expectedLoginOptionsCount})` }))
.exists();
assert.dom(userNavigation.getByRole('link', { name: 'Profil' })).exists();
assert.dom(userNavigation.getByRole('link', { name: `Participations (${expectedParticipationCount})` })).exists();
assert
Expand Down Expand Up @@ -128,8 +134,16 @@ module('Acceptance | authenticated/users/get', function (hooks) {
organizationMemberships: [organizationMembership],
certificationCenterMemberships: [certificationCenterMembership],
});
const expectedLoginOptionsCountBeforeAnonymisation = 3;
const expectedLoginOptionsCountAfterAnonymisation = 0;

const screen = await visit(`/users/${userToAnonymise.id}`);
assert
.dom(
screen.getByRole('link', { name: `Méthodes de connexion (${expectedLoginOptionsCountBeforeAnonymisation})` }),
)
.exists();

await click(screen.getByRole('button', { name: 'Anonymiser cet utilisateur' }));

await screen.findByRole('dialog');
Expand All @@ -140,7 +154,9 @@ module('Acceptance | authenticated/users/get', function (hooks) {
assert.dom(screen.getByText('Nom : (anonymised)')).exists();

// when & then #2
await click(screen.getByRole('link', { name: 'Méthodes de connexion' }));
await click(
screen.getByRole('link', { name: `Méthodes de connexion (${expectedLoginOptionsCountAfterAnonymisation})` }),
);
assert.dom(screen.getByLabelText("L'utilisateur n'a pas de méthode de connexion avec identifiant")).exists();
assert.dom(screen.getByLabelText("L'utilisateur n'a pas de méthode de connexion avec adresse e-mail")).exists();
assert.dom(screen.getByLabelText("L'utilisateur n'a pas de méthode de connexion Médiacentre")).exists();
Expand Down Expand Up @@ -218,11 +234,11 @@ module('Acceptance | authenticated/users/get', function (hooks) {

module('when administrator click on remove authentication method button', function () {
test('not displays remove link and display unchecked icon', async function (assert) {
const expectedLoginOptionsCount = 2;
// given
const user = await _buildAndAuthenticateUser(this.server, { email: 'john.harry@example.net', username: null });
const screen = await visit(`/users/${user.id}`);
await click(screen.getByRole('link', { name: 'Méthodes de connexion' }));

await click(screen.getByRole('link', { name: `Méthodes de connexion (${expectedLoginOptionsCount})` }));
// when
await click(screen.getAllByRole('button', { name: 'Supprimer' })[0]);

Expand Down

0 comments on commit d6a6309

Please sign in to comment.