1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

fix: add user email to project user events

This commit is contained in:
Fredrik Oseberg 2022-03-14 14:06:11 +01:00
parent e15df8764a
commit c3d3280290

View File

@ -37,6 +37,7 @@ import IncompatibleProjectError from '../error/incompatible-project-error';
import { DEFAULT_PROJECT } from '../types/project';
import { IFeatureTagStore } from 'lib/types/stores/feature-tag-store';
import ProjectWithoutOwnerError from '../error/project-without-owner-error';
import { IUserStore } from 'lib/types/stores/user-store';
const getCreatedBy = (user: User) => user.email || user.username;
@ -66,6 +67,8 @@ export default class ProjectService {
private tagStore: IFeatureTagStore;
private userStore: IUserStore;
constructor(
{
projectStore,
@ -75,6 +78,7 @@ export default class ProjectService {
environmentStore,
featureEnvironmentStore,
featureTagStore,
userStore,
}: Pick<
IUnleashStores,
| 'projectStore'
@ -84,6 +88,7 @@ export default class ProjectService {
| 'environmentStore'
| 'featureEnvironmentStore'
| 'featureTagStore'
| 'userStore'
>,
config: IUnleashConfig,
accessService: AccessService,
@ -98,6 +103,7 @@ export default class ProjectService {
this.featureTypeStore = featureTypeStore;
this.featureToggleService = featureToggleService;
this.tagStore = featureTagStore;
this.userStore = userStore;
this.logger = config.getLogger('services/project-service.js');
}
@ -280,6 +286,7 @@ export default class ProjectService {
const [roles, users] = await this.accessService.getProjectRoleUsers(
projectId,
);
const user = await this.userStore.get(userId);
const role = roles.find((r) => r.id === roleId);
if (!role) {
@ -299,7 +306,12 @@ export default class ProjectService {
new ProjectUserAddedEvent({
project: projectId,
createdBy,
data: { roleId, userId, roleName: role.name },
data: {
roleId,
userId,
roleName: role.name,
email: user.email,
},
}),
);
}
@ -317,11 +329,18 @@ export default class ProjectService {
await this.accessService.removeUserFromRole(userId, role.id, projectId);
const user = await this.userStore.get(userId);
await this.eventStore.store(
new ProjectUserRemovedEvent({
project: projectId,
createdBy,
preData: { roleId, userId, roleName: role.name },
preData: {
roleId,
userId,
roleName: role.name,
email: user.email,
},
}),
);
}
@ -389,8 +408,14 @@ export default class ProjectService {
userId,
roleId: currentRole.id,
roleName: currentRole.name,
email: user.email,
},
data: {
userId,
roleId,
roleName: role.name,
email: user.email,
},
data: { userId, roleId, roleName: role.name },
}),
);
}