From 14f1dcf7fa04662b357100eaf8cb55956138c564 Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Mon, 16 Dec 2024 20:26:36 +0100 Subject: [PATCH] feat(admin): display correct message in user overview when account is self deleted --- admin/app/components/users/user-overview.gjs | 8 ++- admin/app/models/user.js | 1 + .../components/users/user-overview-test.gjs | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/admin/app/components/users/user-overview.gjs b/admin/app/components/users/user-overview.gjs index 186cf38f015..1deecd9c92f 100644 --- a/admin/app/components/users/user-overview.gjs +++ b/admin/app/components/users/user-overview.gjs @@ -47,9 +47,11 @@ export default class UserOverview extends Component { } get anonymisationMessage() { - return this.args.user.anonymisedByFullName - ? `Utilisateur anonymisé par ${this.args.user.anonymisedByFullName}.` - : 'Utilisateur anonymisé.'; + return this.args.user.id === String(this.args.user.hasBeenAnonymisedBy) + ? 'Utilisateur anonymisé par lui-même.' + : this.args.user.anonymisedByFullName + ? `Utilisateur anonymisé par ${this.args.user.anonymisedByFullName}.` + : 'Utilisateur anonymisé.'; } get canModifyEmail() { diff --git a/admin/app/models/user.js b/admin/app/models/user.js index 432cfe5b402..6ae3c18b726 100644 --- a/admin/app/models/user.js +++ b/admin/app/models/user.js @@ -19,6 +19,7 @@ export default class User extends Model { @attr() lastLoggedAt; @attr() emailConfirmedAt; @attr() hasBeenAnonymised; + @attr() hasBeenAnonymisedBy; @attr() anonymisedByFullName; @attr() isPixAgent; diff --git a/admin/tests/integration/components/users/user-overview-test.gjs b/admin/tests/integration/components/users/user-overview-test.gjs index f01ed04679e..5692e431c73 100644 --- a/admin/tests/integration/components/users/user-overview-test.gjs +++ b/admin/tests/integration/components/users/user-overview-test.gjs @@ -12,6 +12,63 @@ import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering'; module('Integration | Component | users | user-overview', function (hooks) { setupIntlRenderingTest(hooks); + module('when the user is anonymised', function (hooks) { + class AccessControlStub extends Service { + hasAccessToUsersActionsScope = true; + } + + hooks.beforeEach(function () { + this.owner.register('service:access-control', AccessControlStub); + }); + + module('when the user has self deleted his account', function () { + test('displays the dedicated deletion message', async function (assert) { + // given + + const store = this.owner.lookup('service:store'); + const user = store.createRecord('user', { + id: '123', + firstName: '(anonymised)', + lastName: '(anonymised)', + email: null, + username: null, + hasBeenAnonymised: true, + hasBeenAnonymisedBy: 123, + anonymisedByFullName: '(anonymised) (anonymised)', + }); + + // when + const screen = await render(); + + // then + assert.dom(screen.getByText('Utilisateur anonymisé par lui-même.')).exists(); + }); + }); + + module("when the user's account has been deleted by an admin member", function () { + test("displays the deletion message with the admin member's full name", async function (assert) { + // given + const store = this.owner.lookup('service:store'); + const user = store.createRecord('user', { + id: '123', + firstName: '(anonymised)', + lastName: '(anonymised)', + email: null, + username: null, + hasBeenAnonymised: true, + hasBeenAnonymisedBy: 456, + anonymisedByFullName: 'Laurent Bobine', + }); + + // when + const screen = await render(); + + // then + + assert.dom(screen.getByText('Utilisateur anonymisé par Laurent Bobine.')).exists(); + }); + }); + }); module('when the admin member has access to users actions scope', function (hooks) { class AccessControlStub extends Service { hasAccessToUsersActionsScope = true;