Skip to content

Commit 836c920

Browse files
authored
fix: get all strategies and check if env to be disabled (#9357)
1 parent a6cfcea commit 836c920

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

src/lib/features/feature-toggle/feature-toggle-service.ts

+24
Original file line numberDiff line numberDiff line change
@@ -790,12 +790,35 @@ class FeatureToggleService {
790790
auditUser: IAuditUser,
791791
user?: IUser,
792792
): Promise<void> {
793+
if (this.flagResolver.isEnabled('simplifyDisableFeature')) {
794+
const strategies =
795+
await this.featureStrategiesStore.getStrategiesForFeatureEnv(
796+
projectId,
797+
featureName,
798+
environment,
799+
);
800+
const hasOnlyDisabledStrategies = strategies.every(
801+
(strategy) => strategy.disabled,
802+
);
803+
if (hasOnlyDisabledStrategies) {
804+
await this.unprotectedUpdateEnabled(
805+
projectId,
806+
featureName,
807+
environment,
808+
false,
809+
auditUser,
810+
user,
811+
);
812+
}
813+
return;
814+
}
793815
const feature = await this.getFeature({ featureName });
794816

795817
const env = feature.environments.find((e) => e.name === environment);
796818
const hasOnlyDisabledStrategies = env?.strategies.every(
797819
(strategy) => strategy.disabled,
798820
);
821+
799822
if (hasOnlyDisabledStrategies) {
800823
await this.unprotectedUpdateEnabled(
801824
projectId,
@@ -1090,6 +1113,7 @@ class FeatureToggleService {
10901113
userId,
10911114
archived,
10921115
);
1116+
10931117
return {
10941118
...result,
10951119
dependencies,

src/lib/features/feature-toggle/tests/feature-toggle-service.limit.test.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ describe('Strategy limits', () => {
143143
{
144144
constraints: newConstraints,
145145
},
146-
{ projectId: 'default', featureName: 'feature' } as any,
146+
{
147+
projectId: 'default',
148+
featureName: 'feature',
149+
environment: 'default',
150+
},
147151
{} as IAuditUser,
148152
);
149153

@@ -246,7 +250,11 @@ describe('Strategy limits', () => {
246250
{
247251
constraints: constraints(valueCount),
248252
},
249-
{ projectId: 'default', featureName: 'feature' } as any,
253+
{
254+
projectId: 'default',
255+
featureName: 'feature',
256+
environment: 'default',
257+
},
250258
{} as IAuditUser,
251259
);
252260

src/lib/types/experimental.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export type IFlagKey =
6666
| 'dataUsageMultiMonthView'
6767
| 'consumptionModel'
6868
| 'teamsIntegrationChangeRequests'
69-
| 'edgeObservability';
69+
| 'edgeObservability'
70+
| 'simplifyDisableFeature';
7071

7172
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
7273

@@ -319,6 +320,10 @@ const flags: IFlags = {
319320
process.env.EXPERIMENTAL_EDGE_OBSERVABILITY,
320321
false,
321322
),
323+
simplifyDisableFeature: parseEnvVarBoolean(
324+
process.env.EXPERIMENTAL_SIMPLIFY_DISABLE_FEATURE,
325+
false,
326+
),
322327
};
323328

324329
export const defaultExperimentalOptions: IExperimentalOptions = {

src/server-dev.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ process.nextTick(async () => {
6060
dataUsageMultiMonthView: true,
6161
filterExistingFlagNames: true,
6262
teamsIntegrationChangeRequests: true,
63+
simplifyDisableFeature: true,
6364
},
6465
},
6566
authentication: {

0 commit comments

Comments
 (0)