mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: simplify how we update projects
This commit is contained in:
parent
f0dfe204ee
commit
1924961efa
@ -13,6 +13,7 @@ import {
|
||||
FEATURE_ENVIRONMENT_DISABLED,
|
||||
FEATURE_ENVIRONMENT_ENABLED,
|
||||
FEATURE_METADATA_UPDATED,
|
||||
FEATURE_PROJECT_CHANGE,
|
||||
FEATURE_REVIVED,
|
||||
FEATURE_STALE_OFF,
|
||||
FEATURE_STALE_ON,
|
||||
@ -723,34 +724,30 @@ class FeatureToggleServiceV2 {
|
||||
return { ...legacyFeature, enabled, strategies };
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
// TODO: move to projectService
|
||||
async updateField(
|
||||
async changeProject(
|
||||
featureName: string,
|
||||
field: string,
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
value: any,
|
||||
newProject: string,
|
||||
userName: string,
|
||||
event: string,
|
||||
): Promise<any> {
|
||||
): Promise<void> {
|
||||
const feature = await this.featureToggleStore.get(featureName);
|
||||
feature[field] = value;
|
||||
await this.featureToggleStore.update(feature.project, feature);
|
||||
const oldProject = feature.project;
|
||||
feature.project = newProject;
|
||||
await this.featureToggleStore.update(newProject, feature);
|
||||
|
||||
const tags = await this.featureTagStore.getAllTagsForFeature(
|
||||
featureName,
|
||||
);
|
||||
|
||||
// Workaround to support pre 4.1 format
|
||||
const data = await this.getFeatureToggleLegacy(featureName);
|
||||
|
||||
await this.eventStore.store({
|
||||
type: event,
|
||||
type: FEATURE_PROJECT_CHANGE,
|
||||
createdBy: userName,
|
||||
data,
|
||||
project: data.project,
|
||||
data: {
|
||||
name: feature.name,
|
||||
oldProject,
|
||||
newProject,
|
||||
},
|
||||
project: newProject,
|
||||
tags,
|
||||
});
|
||||
return feature;
|
||||
}
|
||||
|
||||
async getArchivedFeatures(): Promise<FeatureToggle[]> {
|
||||
|
@ -6,7 +6,6 @@ import { nameType } from '../routes/util';
|
||||
import { projectSchema } from './project-schema';
|
||||
import NotFoundError from '../error/notfound-error';
|
||||
import {
|
||||
FEATURE_PROJECT_CHANGE,
|
||||
PROJECT_CREATED,
|
||||
PROJECT_DELETED,
|
||||
PROJECT_UPDATED,
|
||||
@ -222,12 +221,10 @@ export default class ProjectService {
|
||||
if (!isCompatibleWithTargetProject) {
|
||||
throw new IncompatibleProjectError(newProjectId);
|
||||
}
|
||||
const updatedFeature = await this.featureToggleService.updateField(
|
||||
const updatedFeature = await this.featureToggleService.changeProject(
|
||||
featureName,
|
||||
'project',
|
||||
newProjectId,
|
||||
user.username,
|
||||
FEATURE_PROJECT_CHANGE,
|
||||
);
|
||||
await this.featureToggleService.updateFeatureStrategyProject(
|
||||
featureName,
|
||||
|
@ -17,7 +17,7 @@ let db: ITestDb;
|
||||
|
||||
let projectService;
|
||||
let accessService;
|
||||
let featureToggleService;
|
||||
let featureToggleService: FeatureToggleServiceV2;
|
||||
let user;
|
||||
|
||||
beforeAll(async () => {
|
||||
@ -511,13 +511,15 @@ test('should change project when checks pass', async () => {
|
||||
await projectService.createProject(projectDestination, user);
|
||||
await featureToggleService.createFeatureToggle(project.id, toggle, user);
|
||||
|
||||
const updatedFeature = await projectService.changeProject(
|
||||
await projectService.changeProject(
|
||||
projectDestination.id,
|
||||
toggle.name,
|
||||
user,
|
||||
project.id,
|
||||
);
|
||||
|
||||
const updatedFeature = await featureToggleService.getFeature(toggle.name);
|
||||
|
||||
expect(updatedFeature.project).toBe(projectDestination.id);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user