diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index 2a14ec4a70..e882f1b691 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -310,6 +310,22 @@ class FeatureToggleService { strategyConfig: Unsaved, context: IFeatureStrategyContext, createdBy: string, + ): Promise> { + await this.stopWhenChangeRequestsEnabled( + context.projectId, + context.environment, + ); + return this.unprotectedCreateStrategy( + strategyConfig, + context, + createdBy, + ); + } + + async unprotectedCreateStrategy( + strategyConfig: Unsaved, + context: IFeatureStrategyContext, + createdBy: string, ): Promise> { const { featureName, projectId, environment } = context; await this.validateFeatureContext(context); @@ -381,12 +397,24 @@ class FeatureToggleService { * @param context - Which context does this strategy live in (projectId, featureName, environment) * @param userName - Human readable id of the user performing the update */ - async updateStrategy( id: string, updates: Partial, context: IFeatureStrategyContext, userName: string, + ): Promise> { + await this.stopWhenChangeRequestsEnabled( + context.projectId, + context.environment, + ); + return this.unprotectedUpdateStrategy(id, updates, context, userName); + } + + async unprotectedUpdateStrategy( + id: string, + updates: Partial, + context: IFeatureStrategyContext, + userName: string, ): Promise> { const { projectId, environment, featureName } = context; const existingStrategy = await this.featureStrategiesStore.get(id); @@ -494,6 +522,18 @@ class FeatureToggleService { id: string, context: IFeatureStrategyContext, createdBy: string, + ): Promise { + await this.stopWhenChangeRequestsEnabled( + context.projectId, + context.environment, + ); + return this.unprotectedDeleteStrategy(id, context, createdBy); + } + + async unprotectedDeleteStrategy( + id: string, + context: IFeatureStrategyContext, + createdBy: string, ): Promise { const existingStrategy = await this.featureStrategiesStore.get(id); const { featureName, projectId, environment } = context; @@ -919,6 +959,25 @@ class FeatureToggleService { enabled: boolean, createdBy: string, user?: User, + ): Promise { + await this.stopWhenChangeRequestsEnabled(project, environment); + return this.unprotectedUpdateEnabled( + project, + featureName, + environment, + enabled, + createdBy, + user, + ); + } + + async unprotectedUpdateEnabled( + project: string, + featureName: string, + environment: string, + enabled: boolean, + createdBy: string, + user?: User, ): Promise { const hasEnvironment = await this.featureEnvironmentStore.featureHasEnvironment( @@ -1208,6 +1267,22 @@ class FeatureToggleService { }); return variableVariants.concat(fixedVariants); } + + private async stopWhenChangeRequestsEnabled( + project: string, + environment: string, + ) { + if ( + await this.accessService.isChangeRequestsEnabled( + project, + environment, + ) + ) { + throw new Error( + `Change requests are enabled for ${project} in ${environment} environment`, + ); + } + } } export default FeatureToggleService;