From 5603e8683d9da7cca91715634414e496c6917f11 Mon Sep 17 00:00:00 2001 From: David Leek Date: Tue, 19 Dec 2023 10:16:17 +0100 Subject: [PATCH] chore: list users and groups under each role in projectaccessadded event (#5581) ## About the changes Changes the project access added event to list all users and groups added to each role instead of in root event. --- src/lib/routes/admin-api/events.test.ts | 12 +++++++----- src/lib/services/project-service.ts | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/lib/routes/admin-api/events.test.ts b/src/lib/routes/admin-api/events.test.ts index 6f63decc1e..2c86514c52 100644 --- a/src/lib/routes/admin-api/events.test.ts +++ b/src/lib/routes/admin-api/events.test.ts @@ -121,11 +121,13 @@ test('should anonymise any PII fields, no matter the depth', async () => { createdBy: 'some@email.com', createdByUserId: TEST_USER_ID, data: { - groups: [ + roles: [ { - name: 'test', - project: 'default', - users: [{ username: testUsername }], + roleId: 1, + groupIds: [1, 2], + // Doesn't reflect the real data structure for event here, normally a number array. + // Testing PII anonymisation + users: [{ id: 1, username: testUsername }], }, ], }, @@ -138,7 +140,7 @@ test('should anonymise any PII fields, no matter the depth', async () => { .expect(200); expect(body.events.length).toBe(1); - expect(body.events[0].data.groups[0].users[0].username).not.toBe( + expect(body.events[0].data.roles[0].users[0].username).not.toBe( testUsername, ); }); diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index d83a2e2c76..59b323ebdb 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -681,9 +681,11 @@ export default class ProjectService { createdBy, createdByUserId, data: { - roleId, - groups: usersAndGroups.groups.map(({ id }) => id), - users: usersAndGroups.users.map(({ id }) => id), + roles: { + roleId, + groupIds: usersAndGroups.groups.map(({ id }) => id), + userIds: usersAndGroups.users.map(({ id }) => id), + }, }, }), ); @@ -711,9 +713,13 @@ export default class ProjectService { createdBy, createdByUserId, data: { - roles, - groups, - users, + roles: roles.map((roleId) => { + return { + roleId, + groupIds: groups, + userIds: users, + }; + }), }, }), );