mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +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>,
|
strategyConfig: Unsaved<IStrategyConfig>,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
createdBy: string,
|
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>> {
|
): Promise<Saved<IStrategyConfig>> {
|
||||||
const { featureName, projectId, environment } = context;
|
const { featureName, projectId, environment } = context;
|
||||||
await this.validateFeatureContext(context);
|
await this.validateFeatureContext(context);
|
||||||
@ -381,12 +397,24 @@ class FeatureToggleService {
|
|||||||
* @param context - Which context does this strategy live in (projectId, featureName, environment)
|
* @param context - Which context does this strategy live in (projectId, featureName, environment)
|
||||||
* @param userName - Human readable id of the user performing the update
|
* @param userName - Human readable id of the user performing the update
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async updateStrategy(
|
async updateStrategy(
|
||||||
id: string,
|
id: string,
|
||||||
updates: Partial<IFeatureStrategy>,
|
updates: Partial<IFeatureStrategy>,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
userName: string,
|
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>> {
|
): Promise<Saved<IStrategyConfig>> {
|
||||||
const { projectId, environment, featureName } = context;
|
const { projectId, environment, featureName } = context;
|
||||||
const existingStrategy = await this.featureStrategiesStore.get(id);
|
const existingStrategy = await this.featureStrategiesStore.get(id);
|
||||||
@ -494,6 +522,18 @@ class FeatureToggleService {
|
|||||||
id: string,
|
id: string,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
createdBy: string,
|
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> {
|
): Promise<void> {
|
||||||
const existingStrategy = await this.featureStrategiesStore.get(id);
|
const existingStrategy = await this.featureStrategiesStore.get(id);
|
||||||
const { featureName, projectId, environment } = context;
|
const { featureName, projectId, environment } = context;
|
||||||
@ -919,6 +959,25 @@ class FeatureToggleService {
|
|||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
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> {
|
): Promise<FeatureToggle> {
|
||||||
const hasEnvironment =
|
const hasEnvironment =
|
||||||
await this.featureEnvironmentStore.featureHasEnvironment(
|
await this.featureEnvironmentStore.featureHasEnvironment(
|
||||||
@ -1208,6 +1267,22 @@ class FeatureToggleService {
|
|||||||
});
|
});
|
||||||
return variableVariants.concat(fixedVariants);
|
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;
|
export default FeatureToggleService;
|
||||||
|
Loading…
Reference in New Issue
Block a user