diff --git a/src/lib/routes/admin-api/project/project-features.ts b/src/lib/routes/admin-api/project/project-features.ts index 5bb7b29d42..d6bda03872 100644 --- a/src/lib/routes/admin-api/project/project-features.ts +++ b/src/lib/routes/admin-api/project/project-features.ts @@ -723,7 +723,20 @@ export default class ProjectFeaturesController extends Controller { >, res: Response, ): Promise { - res.status(405).end(); + const { environment, projectId } = req.params; + const { shouldActivateDisabledStrategies } = req.query; + const { features } = req.body; + + await this.featureService.bulkUpdateEnabled( + projectId, + features, + environment, + true, + extractUsername(req), + req.user, + shouldActivateDisabledStrategies === 'true', + ); + res.status(200).end(); } async bulkToggleFeaturesEnvironmentOff( @@ -735,7 +748,20 @@ export default class ProjectFeaturesController extends Controller { >, res: Response, ): Promise { - res.status(405).end(); + const { environment, projectId } = req.params; + const { shouldActivateDisabledStrategies } = req.query; + const { features } = req.body; + + await this.featureService.bulkUpdateEnabled( + projectId, + features, + environment, + false, + extractUsername(req), + req.user, + shouldActivateDisabledStrategies === 'true', + ); + res.status(200).end(); } async toggleFeatureEnvironmentOff( diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index 8f9200dc97..8c7745dca1 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -1257,6 +1257,30 @@ class FeatureToggleService { ); } + async bulkUpdateEnabled( + project: string, + featureNames: string[], + environment: string, + enabled: boolean, + createdBy: string, + user?: User, + shouldActivateDisabledStrategies = false, + ): Promise { + await Promise.all( + featureNames.map((featureName) => + this.updateEnabled( + project, + featureName, + environment, + enabled, + createdBy, + user, + shouldActivateDisabledStrategies, + ), + ), + ); + } + async updateEnabled( project: string, featureName: string, diff --git a/src/test/e2e/api/admin/project/features.e2e.test.ts b/src/test/e2e/api/admin/project/features.e2e.test.ts index af6fd51e28..e7cf9f4f36 100644 --- a/src/test/e2e/api/admin/project/features.e2e.test.ts +++ b/src/test/e2e/api/admin/project/features.e2e.test.ts @@ -413,14 +413,28 @@ test('Can bulk enable/disable environment for feature with strategies', async () ) .send({ features: [featureName] }) .set('Content-Type', 'application/json') - .expect(405); + .expect(200); + await app.getProjectFeatures(project, featureName).expect((res) => { + const enabledFeatureEnv = res.body.environments.find( + (e) => e.name === envName, + ); + expect(enabledFeatureEnv).toBeTruthy(); + expect(enabledFeatureEnv.enabled).toBe(true); + }); await app.request .post( `/api/admin/projects/${project}/bulk_features/environments/${envName}/off`, ) .send({ features: [featureName] }) - .expect(405); + .expect(200); + await app.getProjectFeatures(project, featureName).expect((res) => { + const disabledFeatureEnv = res.body.environments.find( + (e) => e.name === envName, + ); + expect(disabledFeatureEnv).toBeTruthy(); + expect(disabledFeatureEnv.enabled).toBe(false); + }); }); test("Trying to get a project that doesn't exist yields 404", async () => {