Skip to content

Commit

Permalink
fix: add event for changeProject
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikOseberg committed Jan 11, 2022
1 parent e8db1da commit 808a9f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
22 changes: 0 additions & 22 deletions src/lib/services/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,28 +834,6 @@ class FeatureToggleService {
return { ...legacyFeature, enabled, strategies };
}

async changeProject(
featureName: string,
newProject: string,
createdBy: string,
): Promise<void> {
const feature = await this.featureToggleStore.get(featureName);
const oldProject = feature.project;
feature.project = newProject;
await this.featureToggleStore.update(newProject, feature);

const tags = await this.tagStore.getAllTagsForFeature(featureName);
await this.eventStore.store(
new FeatureChangeProjectEvent({
createdBy,
oldProject,
newProject,
featureName,
tags,
}),
);
}

async getArchivedFeatures(): Promise<FeatureToggle[]> {
return this.getFeatureToggles({}, true);
}
Expand Down
24 changes: 19 additions & 5 deletions src/lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { nameType } from '../routes/util';
import { projectSchema } from './project-schema';
import NotFoundError from '../error/notfound-error';
import {
FeatureChangeProjectEvent,
PROJECT_CREATED,
PROJECT_DELETED,
PROJECT_UPDATED,
Expand All @@ -28,14 +29,11 @@ import { IProjectQuery, IProjectStore } from '../types/stores/project-store';
import { IRoleDescriptor } from '../types/stores/access-store';
import { IEventStore } from '../types/stores/event-store';
import FeatureToggleService from './feature-toggle-service';
import {
CREATE_FEATURE,
MOVE_FEATURE_TOGGLE,
UPDATE_FEATURE,
} from '../types/permissions';
import { MOVE_FEATURE_TOGGLE } from '../types/permissions';
import NoAccessError from '../error/no-access-error';
import IncompatibleProjectError from '../error/incompatible-project-error';
import { DEFAULT_PROJECT } from '../types/project';
import { IFeatureTagStore } from 'lib/types/stores/feature-tag-store';

const getCreatedBy = (user: User) => user.email || user.username;

Expand Down Expand Up @@ -63,6 +61,8 @@ export default class ProjectService {

private featureToggleService: FeatureToggleService;

private tagStore: IFeatureTagStore;

constructor(
{
projectStore,
Expand All @@ -71,6 +71,7 @@ export default class ProjectService {
featureTypeStore,
environmentStore,
featureEnvironmentStore,
featureTagStore,
}: Pick<
IUnleashStores,
| 'projectStore'
Expand All @@ -79,6 +80,7 @@ export default class ProjectService {
| 'featureTypeStore'
| 'environmentStore'
| 'featureEnvironmentStore'
| 'featureTagStore'
>,
config: IUnleashConfig,
accessService: AccessService,
Expand All @@ -92,6 +94,7 @@ export default class ProjectService {
this.featureToggleStore = featureToggleStore;
this.featureTypeStore = featureTypeStore;
this.featureToggleService = featureToggleService;
this.tagStore = featureTagStore;
this.logger = config.getLogger('services/project-service.js');
}

Expand Down Expand Up @@ -224,6 +227,17 @@ export default class ProjectService {
newProjectId,
);

const tags = await this.tagStore.getAllTagsForFeature(featureName);
await this.eventStore.store(
new FeatureChangeProjectEvent({
createdBy: user.username,
oldProject: currentProjectId,
newProject: newProjectId,
featureName,
tags,
}),
);

return updatedFeature;
}

Expand Down

0 comments on commit 808a9f5

Please sign in to comment.