Skip to content

Commit

Permalink
feat(admin): display correct message in user overview when account is…
Browse files Browse the repository at this point in the history
… self deleted
  • Loading branch information
EmmanuelleBonnemay committed Dec 17, 2024
1 parent cf31944 commit 14f1dcf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
8 changes: 5 additions & 3 deletions admin/app/components/users/user-overview.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions admin/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class User extends Model {
@attr() lastLoggedAt;
@attr() emailConfirmedAt;
@attr() hasBeenAnonymised;
@attr() hasBeenAnonymisedBy;
@attr() anonymisedByFullName;
@attr() isPixAgent;

Expand Down
57 changes: 57 additions & 0 deletions admin/tests/integration/components/users/user-overview-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(<template><UserOverview @user={{user}} /></template>);

// 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(<template><UserOverview @user={{user}} /></template>);

// 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;
Expand Down

0 comments on commit 14f1dcf

Please sign in to comment.