Skip to content

Commit 3fc0b4f

Browse files
author
Theotime2005
authored
feat(admin): add the date of pix authentication method
1 parent b838d91 commit 3fc0b4f

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

admin/app/components/users/user-detail-personal-information/authentication-method.gjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { action } from '@ember/object';
55
import { service } from '@ember/service';
66
import Component from '@glimmer/component';
77
import { tracked } from '@glimmer/tracking';
8+
import dayjs from 'dayjs';
89
import dayjsFormat from 'ember-dayjs/helpers/dayjs-format';
910
import { t } from 'ember-intl';
1011

@@ -15,6 +16,7 @@ import ReassignOidcAuthenticationMethodModal from './reassign-oidc-authenticatio
1516
export default class AuthenticationMethod extends Component {
1617
@service pixToast;
1718
@service accessControl;
19+
@service intl;
1820
@service oidcIdentityProviders;
1921

2022
@tracked showAddAuthenticationMethodModal = false;
@@ -87,12 +89,15 @@ export default class AuthenticationMethod extends Component {
8789
get emailAuthenticationMethod() {
8890
return { code: 'EMAIL', name: 'Adresse e-mail' };
8991
}
92+
9093
get userNameAuthenticationMethod() {
9194
return { code: 'USERNAME', name: 'Identifiant' };
9295
}
96+
9397
get garAuthenticationMethod() {
9498
return { code: 'GAR', name: 'Médiacentre' };
9599
}
100+
96101
get userOidcAuthenticationMethods() {
97102
return this.oidcIdentityProviders.list.map((oidcIdentityProvider) => {
98103
const userHasThisOidcAuthenticationMethod = this.authenticationMethods.any(
@@ -110,6 +115,29 @@ export default class AuthenticationMethod extends Component {
110115
});
111116
}
112117

118+
get pixLastLoggedAtAuthenticationMethod() {
119+
const method = this.authenticationMethods.find((method) => method.identityProvider === 'PIX');
120+
return method ? this._displayAuthenticationMethodDate(method.lastLoggedAt) : null;
121+
}
122+
123+
get garLastLoggedAtAuthenticationMethod() {
124+
const method = this.authenticationMethods.find((method) => method.identityProvider === 'GAR');
125+
return method ? this._displayAuthenticationMethodDate(method.lastLoggedAt) : null;
126+
}
127+
128+
_displayAuthenticationMethodDate(date) {
129+
if (!date) return null;
130+
return this.intl.t('components.users.user-detail-personal-information.authentication-method.last-logged-at', {
131+
date: dayjs(date).format('DD/MM/YYYY'),
132+
});
133+
}
134+
135+
@action
136+
oidcLastLoggedAtAuthenticationMethod(oidc) {
137+
const method = this.authenticationMethods.find((method) => method.identityProvider === oidc.code);
138+
return method ? this._displayAuthenticationMethodDate(method.lastLoggedAt) : null;
139+
}
140+
113141
@action
114142
onChangeNewEmail(event) {
115143
this.newEmail = event.target.value;
@@ -244,6 +272,7 @@ export default class AuthenticationMethod extends Component {
244272
/>
245273
{{/if}}
246274
</td>
275+
<td>{{this.pixLastLoggedAtAuthenticationMethod}}</td>
247276
<td>
248277
{{#if this.accessControl.hasAccessToUsersActionsScope}}
249278
{{#if this.isAllowedToRemoveEmailAuthenticationMethod}}
@@ -284,6 +313,7 @@ export default class AuthenticationMethod extends Component {
284313
/>
285314
{{/if}}
286315
</td>
316+
<td>{{this.pixLastLoggedAtAuthenticationMethod}}</td>
287317
<td>
288318
{{#if this.accessControl.hasAccessToUsersActionsScope}}
289319
{{#if this.isAllowedToRemoveUsernameAuthenticationMethod}}
@@ -319,6 +349,7 @@ export default class AuthenticationMethod extends Component {
319349
/>
320350
{{/if}}
321351
</td>
352+
<td>{{this.garLastLoggedAtAuthenticationMethod}}</td>
322353
<td class="authentication-method-table__actions-column">
323354
{{#if this.accessControl.hasAccessToUsersActionsScope}}
324355
<div>
@@ -361,6 +392,7 @@ export default class AuthenticationMethod extends Component {
361392
/>
362393
{{/if}}
363394
</td>
395+
<td>{{this.oidcLastLoggedAtAuthenticationMethod userOidcAuthenticationMethod}}</td>
364396
<td class="authentication-method-table__actions-column">
365397
{{#if this.accessControl.hasAccessToUsersActionsScope}}
366398
<div>

admin/tests/integration/components/users/user-detail-personal-information/authentication-method-test.gjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ module('Integration | Component | users | user-detail-personal-information | aut
133133
)
134134
.exists();
135135
});
136+
136137
test('it displays user has not to change password', async function (assert) {
137138
// given
138139
const user = {
@@ -163,6 +164,37 @@ module('Integration | Component | users | user-detail-personal-information | aut
163164
)
164165
.exists();
165166
});
167+
168+
test('it displays the last logged at with PIX authentication method', async function (assert) {
169+
// given
170+
const user = {
171+
authenticationMethods: [
172+
{
173+
identityProvider: 'PIX',
174+
authenticationComplement: {},
175+
lastLoggedAt: new Date('2022-07-01T00:00:00Z'),
176+
},
177+
],
178+
};
179+
this.owner.register('service:access-control', AccessControlStub);
180+
181+
// when
182+
const screen = await render(<template><AuthenticationMethod @user={{user}} /></template>);
183+
184+
// then
185+
const expectedLabel = t(
186+
'components.users.user-detail-personal-information.authentication-method.last-logged-at',
187+
);
188+
const expectedValue = '01/07/2022';
189+
assert
190+
.dom(
191+
screen.getAllByRole('listitem').find((listItem) => {
192+
const childrenText = listItem.textContent.trim().split('\n');
193+
return childrenText[0]?.trim() === expectedLabel && childrenText[1]?.trim() === expectedValue;
194+
}),
195+
)
196+
.exists();
197+
});
166198
});
167199

168200
module('email authentication method', function () {

admin/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@
440440
"copy-username": "Copy user id"
441441
},
442442
"authentication-method": {
443+
"last-logged-at": "Last logged at {date}",
443444
"should-change-password-status": "Temporary password :"
444445
},
445446
"cgu": {

admin/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@
450450
"copy-username": "Copier l’identifiant"
451451
},
452452
"authentication-method": {
453+
"last-logged-at": "Dernière connexion le {date}",
453454
"should-change-password-status": "Mot de passe temporaire :"
454455
},
455456
"cgu": {

0 commit comments

Comments
 (0)