mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
separate protected and unprotected routes (#2466)
This commit is contained in:
parent
51ccf65367
commit
ac65778cfa
@ -310,6 +310,22 @@ class FeatureToggleService {
|
||||
strategyConfig: Unsaved<IStrategyConfig>,
|
||||
context: IFeatureStrategyContext,
|
||||
createdBy: string,
|
||||
): Promise<Saved<IStrategyConfig>> {
|
||||
await this.stopWhenChangeRequestsEnabled(
|
||||
context.projectId,
|
||||
context.environment,
|
||||
);
|
||||
return this.unprotectedCreateStrategy(
|
||||
strategyConfig,
|
||||
context,
|
||||
createdBy,
|
||||
);
|
||||
}
|
||||
|
||||
async unprotectedCreateStrategy(
|
||||
strategyConfig: Unsaved<IStrategyConfig>,
|
||||
context: IFeatureStrategyContext,
|
||||
createdBy: string,
|
||||
): Promise<Saved<IStrategyConfig>> {
|
||||
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<IFeatureStrategy>,
|
||||
context: IFeatureStrategyContext,
|
||||
userName: string,
|
||||
): Promise<Saved<IStrategyConfig>> {
|
||||
await this.stopWhenChangeRequestsEnabled(
|
||||
context.projectId,
|
||||
context.environment,
|
||||
);
|
||||
return this.unprotectedUpdateStrategy(id, updates, context, userName);
|
||||
}
|
||||
|
||||
async unprotectedUpdateStrategy(
|
||||
id: string,
|
||||
updates: Partial<IFeatureStrategy>,
|
||||
context: IFeatureStrategyContext,
|
||||
userName: string,
|
||||
): Promise<Saved<IStrategyConfig>> {
|
||||
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<void> {
|
||||
await this.stopWhenChangeRequestsEnabled(
|
||||
context.projectId,
|
||||
context.environment,
|
||||
);
|
||||
return this.unprotectedDeleteStrategy(id, context, createdBy);
|
||||
}
|
||||
|
||||
async unprotectedDeleteStrategy(
|
||||
id: string,
|
||||
context: IFeatureStrategyContext,
|
||||
createdBy: string,
|
||||
): Promise<void> {
|
||||
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<FeatureToggle> {
|
||||
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<FeatureToggle> {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user