mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Fix/add project events (#1267)
* fix: wip project events * fix: Include deletion events for when a user is removed from a project role Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
This commit is contained in:
parent
e164e3d835
commit
dc920e85ba
@ -6,6 +6,8 @@ import { nameType } from '../routes/util';
|
||||
import { projectSchema } from './project-schema';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import {
|
||||
ProjectUserAddedEvent,
|
||||
ProjectUserRemovedEvent,
|
||||
PROJECT_CREATED,
|
||||
PROJECT_DELETED,
|
||||
PROJECT_UPDATED,
|
||||
@ -283,11 +285,12 @@ export default class ProjectService {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: should be an event too
|
||||
// TODO: Remove the optional nature of createdBy - this in place to make sure enterprise is compatible
|
||||
async addUser(
|
||||
projectId: string,
|
||||
roleId: number,
|
||||
userId: number,
|
||||
createdBy?: string,
|
||||
): Promise<void> {
|
||||
const [roles, users] = await this.accessService.getProjectRoleUsers(
|
||||
projectId,
|
||||
@ -306,13 +309,22 @@ export default class ProjectService {
|
||||
}
|
||||
|
||||
await this.accessService.addUserToRole(userId, role.id, projectId);
|
||||
|
||||
await this.eventStore.store(
|
||||
new ProjectUserAddedEvent({
|
||||
project: projectId,
|
||||
createdBy,
|
||||
data: { roleId, userId, roleName: role.name },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: should be an event too
|
||||
// TODO: Remove the optional nature of createdBy - this in place to make sure enterprise is compatible
|
||||
async removeUser(
|
||||
projectId: string,
|
||||
roleId: number,
|
||||
userId: number,
|
||||
createdBy?: string,
|
||||
): Promise<void> {
|
||||
const roles = await this.accessService.getRolesForProject(projectId);
|
||||
const role = roles.find((r) => r.id === roleId);
|
||||
@ -333,6 +345,14 @@ export default class ProjectService {
|
||||
}
|
||||
|
||||
await this.accessService.removeUserFromRole(userId, role.id, projectId);
|
||||
|
||||
await this.eventStore.store(
|
||||
new ProjectUserRemovedEvent({
|
||||
project: projectId,
|
||||
createdBy,
|
||||
preData: { roleId, userId, roleName: role.name },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async getMembers(projectId: string): Promise<number> {
|
||||
|
@ -39,6 +39,8 @@ export const PROJECT_CREATED = 'project-created';
|
||||
export const PROJECT_UPDATED = 'project-updated';
|
||||
export const PROJECT_DELETED = 'project-deleted';
|
||||
export const PROJECT_IMPORT = 'project-import';
|
||||
export const PROJECT_USER_ADDED = 'project-user-added';
|
||||
export const PROJECT_USER_REMOVED = 'project-user-removed';
|
||||
export const DROP_PROJECTS = 'drop-projects';
|
||||
export const TAG_CREATED = 'tag-created';
|
||||
export const TAG_DELETED = 'tag-deleted';
|
||||
@ -378,3 +380,35 @@ export class FeatureStrategyRemoveEvent extends BaseEvent {
|
||||
this.preData = preData;
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectUserAddedEvent extends BaseEvent {
|
||||
readonly project: string;
|
||||
|
||||
readonly data: any;
|
||||
|
||||
readonly preData: any;
|
||||
|
||||
constructor(p: { project: string; createdBy: string; data: any }) {
|
||||
super(PROJECT_USER_ADDED, p.createdBy);
|
||||
const { project, data } = p;
|
||||
this.project = project;
|
||||
this.data = data;
|
||||
this.preData = null;
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectUserRemovedEvent extends BaseEvent {
|
||||
readonly project: string;
|
||||
|
||||
readonly data: any;
|
||||
|
||||
readonly preData: any;
|
||||
|
||||
constructor(p: { project: string; createdBy: string; preData: any }) {
|
||||
super(PROJECT_USER_REMOVED, p.createdBy);
|
||||
const { project, preData } = p;
|
||||
this.project = project;
|
||||
this.data = null;
|
||||
this.preData = preData;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user