Skip to content

Commit

Permalink
Fix/user added event (#1437)
Browse files Browse the repository at this point in the history
* 4.9.0-beta.1

* chore: update unleash frontend

* 4.9.0-beta.2

* fix: add user email to project user events
  • Loading branch information
FredrikOseberg committed Mar 16, 2022
1 parent 9c3683c commit a236a61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "unleash-server",
"description": "Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.",
"version": "4.9.0-beta.0",
"version": "4.9.0-beta.2",
"keywords": [
"unleash",
"feature toggle",
Expand Down
31 changes: 28 additions & 3 deletions src/lib/services/project-service.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -66,6 +67,8 @@ export default class ProjectService {

private tagStore: IFeatureTagStore;

private userStore: IUserStore;

constructor(
{
projectStore,
Expand All @@ -75,6 +78,7 @@ export default class ProjectService {
environmentStore,
featureEnvironmentStore,
featureTagStore,
userStore,
}: Pick<
IUnleashStores,
| 'projectStore'
Expand All @@ -84,6 +88,7 @@ export default class ProjectService {
| 'environmentStore'
| 'featureEnvironmentStore'
| 'featureTagStore'
| 'userStore'
>,
config: IUnleashConfig,
accessService: AccessService,
Expand All @@ -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');
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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,
},
}),
);
}
Expand All @@ -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,
},
}),
);
}
Expand Down Expand Up @@ -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 },
}),
);
}
Expand Down

0 comments on commit a236a61

Please sign in to comment.