1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-18 13:48:58 +02:00

feat: improve the format of project-access-added event

This commit is contained in:
David Leek 2023-11-30 08:06:40 +01:00
parent ef8edf9c44
commit ae0b2a108c
No known key found for this signature in database
GPG Key ID: 515EE0F1BB6D0BE1
3 changed files with 46 additions and 12 deletions

View File

@ -116,13 +116,26 @@ test('should anonymise any PII fields, no matter the depth', async () => {
new ProjectAccessAddedEvent({
createdBy: 'some@email.com',
data: {
groups: [
{
name: 'test',
project: 'default',
roles: {
1: {
roleId: 1,
groups: [
{
id: 4,
},
],
users: [{ username: testUsername }],
},
],
},
},
preData: {
roles: {
1: {
roleId: 1,
groups: [],
users: [],
},
},
},
project: 'default',
}),
@ -133,7 +146,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[1].users[0].username).not.toBe(
testUsername,
);
});

View File

@ -664,6 +664,7 @@ export default class ProjectService {
groups: usersAndGroups.groups.map(({ id }) => id),
users: usersAndGroups.users.map(({ id }) => id),
},
preData: {},
}),
);
}
@ -688,9 +689,24 @@ export default class ProjectService {
project: projectId,
createdBy,
data: {
roles,
groups,
users,
roles: roles.reduce((prev, curr) => {
prev[curr] = {
roleId: curr,
groups,
users,
};
return prev;
}, {}),
},
preData: {
roles: roles.reduce((prev, curr) => {
prev[curr] = {
roleId: curr,
groups: [],
users: [],
};
return prev;
}, {}),
},
}),
);

View File

@ -863,12 +863,17 @@ export class ProjectAccessAddedEvent extends BaseEvent {
/**
* @param createdBy accepts a string for backward compatibility. Prefer using IUser for standardization
*/
constructor(p: { project: string; createdBy: string | IUser; data: any }) {
constructor(p: {
project: string;
createdBy: string | IUser;
data: any;
preData: any;
}) {
super(PROJECT_ACCESS_ADDED, p.createdBy);
const { project, data } = p;
const { project, data, preData } = p;
this.project = project;
this.data = data;
this.preData = null;
this.preData = preData;
}
}