mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
CR applier should be able to create strategy (#2597)
This commit is contained in:
parent
a65a47e3b5
commit
b9290dd5ed
@ -1015,13 +1015,21 @@ class FeatureToggleService {
|
|||||||
user?: User,
|
user?: User,
|
||||||
): Promise<FeatureToggle> {
|
): Promise<FeatureToggle> {
|
||||||
await this.stopWhenChangeRequestsEnabled(project, environment);
|
await this.stopWhenChangeRequestsEnabled(project, environment);
|
||||||
|
if (enabled) {
|
||||||
|
await this.stopWhenCannotCreateStrategies(
|
||||||
|
project,
|
||||||
|
environment,
|
||||||
|
featureName,
|
||||||
|
user,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return this.unprotectedUpdateEnabled(
|
return this.unprotectedUpdateEnabled(
|
||||||
project,
|
project,
|
||||||
featureName,
|
featureName,
|
||||||
environment,
|
environment,
|
||||||
enabled,
|
enabled,
|
||||||
createdBy,
|
createdBy,
|
||||||
user,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1031,7 +1039,6 @@ class FeatureToggleService {
|
|||||||
environment: string,
|
environment: string,
|
||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
|
||||||
): Promise<FeatureToggle> {
|
): Promise<FeatureToggle> {
|
||||||
const hasEnvironment =
|
const hasEnvironment =
|
||||||
await this.featureEnvironmentStore.featureHasEnvironment(
|
await this.featureEnvironmentStore.featureHasEnvironment(
|
||||||
@ -1039,7 +1046,12 @@ class FeatureToggleService {
|
|||||||
featureName,
|
featureName,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (hasEnvironment) {
|
if (!hasEnvironment) {
|
||||||
|
throw new NotFoundError(
|
||||||
|
`Could not find environment ${environment} for feature: ${featureName}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
const strategies = await this.getStrategiesForEnvironment(
|
const strategies = await this.getStrategiesForEnvironment(
|
||||||
project,
|
project,
|
||||||
@ -1047,15 +1059,6 @@ class FeatureToggleService {
|
|||||||
environment,
|
environment,
|
||||||
);
|
);
|
||||||
if (strategies.length === 0) {
|
if (strategies.length === 0) {
|
||||||
const canAddStrategies =
|
|
||||||
user &&
|
|
||||||
(await this.accessService.hasPermission(
|
|
||||||
user,
|
|
||||||
CREATE_FEATURE_STRATEGY,
|
|
||||||
project,
|
|
||||||
environment,
|
|
||||||
));
|
|
||||||
if (canAddStrategies) {
|
|
||||||
await this.unprotectedCreateStrategy(
|
await this.unprotectedCreateStrategy(
|
||||||
getDefaultStrategy(featureName),
|
getDefaultStrategy(featureName),
|
||||||
{
|
{
|
||||||
@ -1065,9 +1068,6 @@ class FeatureToggleService {
|
|||||||
},
|
},
|
||||||
createdBy,
|
createdBy,
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
throw new NoAccessError(CREATE_FEATURE_STRATEGY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const updatedEnvironmentStatus =
|
const updatedEnvironmentStatus =
|
||||||
@ -1079,9 +1079,7 @@ class FeatureToggleService {
|
|||||||
const feature = await this.featureToggleStore.get(featureName);
|
const feature = await this.featureToggleStore.get(featureName);
|
||||||
|
|
||||||
if (updatedEnvironmentStatus > 0) {
|
if (updatedEnvironmentStatus > 0) {
|
||||||
const tags = await this.tagStore.getAllTagsForFeature(
|
const tags = await this.tagStore.getAllTagsForFeature(featureName);
|
||||||
featureName,
|
|
||||||
);
|
|
||||||
await this.eventStore.store(
|
await this.eventStore.store(
|
||||||
new FeatureEnvironmentEvent({
|
new FeatureEnvironmentEvent({
|
||||||
enabled,
|
enabled,
|
||||||
@ -1096,11 +1094,6 @@ class FeatureToggleService {
|
|||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotFoundError(
|
|
||||||
`Could not find environment ${environment} for feature: ${featureName}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @deprecated
|
// @deprecated
|
||||||
async storeFeatureUpdatedEventLegacy(
|
async storeFeatureUpdatedEventLegacy(
|
||||||
featureName: string,
|
featureName: string,
|
||||||
@ -1394,6 +1387,40 @@ class FeatureToggleService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async stopWhenCannotCreateStrategies(
|
||||||
|
project: string,
|
||||||
|
environment: string,
|
||||||
|
featureName: string,
|
||||||
|
user: User,
|
||||||
|
) {
|
||||||
|
const hasEnvironment =
|
||||||
|
await this.featureEnvironmentStore.featureHasEnvironment(
|
||||||
|
environment,
|
||||||
|
featureName,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasEnvironment) {
|
||||||
|
const strategies = await this.getStrategiesForEnvironment(
|
||||||
|
project,
|
||||||
|
featureName,
|
||||||
|
environment,
|
||||||
|
);
|
||||||
|
if (strategies.length === 0) {
|
||||||
|
const canAddStrategies =
|
||||||
|
user &&
|
||||||
|
(await this.accessService.hasPermission(
|
||||||
|
user,
|
||||||
|
CREATE_FEATURE_STRATEGY,
|
||||||
|
project,
|
||||||
|
environment,
|
||||||
|
));
|
||||||
|
if (!canAddStrategies) {
|
||||||
|
throw new NoAccessError(CREATE_FEATURE_STRATEGY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FeatureToggleService;
|
export default FeatureToggleService;
|
||||||
|
Loading…
Reference in New Issue
Block a user