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

fix: simplify how we update projects

This commit is contained in:
Ivar Conradi Østhus 2021-10-21 21:06:56 +02:00
parent f0dfe204ee
commit 1924961efa
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
3 changed files with 20 additions and 24 deletions

View File

@ -13,6 +13,7 @@ import {
FEATURE_ENVIRONMENT_DISABLED, FEATURE_ENVIRONMENT_DISABLED,
FEATURE_ENVIRONMENT_ENABLED, FEATURE_ENVIRONMENT_ENABLED,
FEATURE_METADATA_UPDATED, FEATURE_METADATA_UPDATED,
FEATURE_PROJECT_CHANGE,
FEATURE_REVIVED, FEATURE_REVIVED,
FEATURE_STALE_OFF, FEATURE_STALE_OFF,
FEATURE_STALE_ON, FEATURE_STALE_ON,
@ -723,34 +724,30 @@ class FeatureToggleServiceV2 {
return { ...legacyFeature, enabled, strategies }; return { ...legacyFeature, enabled, strategies };
} }
// @deprecated async changeProject(
// TODO: move to projectService
async updateField(
featureName: string, featureName: string,
field: string, newProject: string,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
value: any,
userName: string, userName: string,
event: string, ): Promise<void> {
): Promise<any> {
const feature = await this.featureToggleStore.get(featureName); const feature = await this.featureToggleStore.get(featureName);
feature[field] = value; const oldProject = feature.project;
await this.featureToggleStore.update(feature.project, feature); feature.project = newProject;
await this.featureToggleStore.update(newProject, feature);
const tags = await this.featureTagStore.getAllTagsForFeature( const tags = await this.featureTagStore.getAllTagsForFeature(
featureName, featureName,
); );
// Workaround to support pre 4.1 format
const data = await this.getFeatureToggleLegacy(featureName);
await this.eventStore.store({ await this.eventStore.store({
type: event, type: FEATURE_PROJECT_CHANGE,
createdBy: userName, createdBy: userName,
data, data: {
project: data.project, name: feature.name,
oldProject,
newProject,
},
project: newProject,
tags, tags,
}); });
return feature;
} }
async getArchivedFeatures(): Promise<FeatureToggle[]> { async getArchivedFeatures(): Promise<FeatureToggle[]> {

View File

@ -6,7 +6,6 @@ import { nameType } from '../routes/util';
import { projectSchema } from './project-schema'; import { projectSchema } from './project-schema';
import NotFoundError from '../error/notfound-error'; import NotFoundError from '../error/notfound-error';
import { import {
FEATURE_PROJECT_CHANGE,
PROJECT_CREATED, PROJECT_CREATED,
PROJECT_DELETED, PROJECT_DELETED,
PROJECT_UPDATED, PROJECT_UPDATED,
@ -222,12 +221,10 @@ export default class ProjectService {
if (!isCompatibleWithTargetProject) { if (!isCompatibleWithTargetProject) {
throw new IncompatibleProjectError(newProjectId); throw new IncompatibleProjectError(newProjectId);
} }
const updatedFeature = await this.featureToggleService.updateField( const updatedFeature = await this.featureToggleService.changeProject(
featureName, featureName,
'project',
newProjectId, newProjectId,
user.username, user.username,
FEATURE_PROJECT_CHANGE,
); );
await this.featureToggleService.updateFeatureStrategyProject( await this.featureToggleService.updateFeatureStrategyProject(
featureName, featureName,

View File

@ -17,7 +17,7 @@ let db: ITestDb;
let projectService; let projectService;
let accessService; let accessService;
let featureToggleService; let featureToggleService: FeatureToggleServiceV2;
let user; let user;
beforeAll(async () => { beforeAll(async () => {
@ -511,13 +511,15 @@ test('should change project when checks pass', async () => {
await projectService.createProject(projectDestination, user); await projectService.createProject(projectDestination, user);
await featureToggleService.createFeatureToggle(project.id, toggle, user); await featureToggleService.createFeatureToggle(project.id, toggle, user);
const updatedFeature = await projectService.changeProject( await projectService.changeProject(
projectDestination.id, projectDestination.id,
toggle.name, toggle.name,
user, user,
project.id, project.id,
); );
const updatedFeature = await featureToggleService.getFeature(toggle.name);
expect(updatedFeature.project).toBe(projectDestination.id); expect(updatedFeature.project).toBe(projectDestination.id);
}); });