1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat: Basic bulk update implementation (#3794)

This commit is contained in:
Mateusz Kwasniewski 2023-05-17 12:20:32 +02:00 committed by GitHub
parent 6d473164ab
commit 6b41cf03a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 4 deletions

View File

@ -723,7 +723,20 @@ export default class ProjectFeaturesController extends Controller {
>,
res: Response<void>,
): Promise<void> {
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<void>,
): Promise<void> {
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(

View File

@ -1257,6 +1257,30 @@ class FeatureToggleService {
);
}
async bulkUpdateEnabled(
project: string,
featureNames: string[],
environment: string,
enabled: boolean,
createdBy: string,
user?: User,
shouldActivateDisabledStrategies = false,
): Promise<void> {
await Promise.all(
featureNames.map((featureName) =>
this.updateEnabled(
project,
featureName,
environment,
enabled,
createdBy,
user,
shouldActivateDisabledStrategies,
),
),
);
}
async updateEnabled(
project: string,
featureName: string,

View File

@ -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 () => {