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:
parent
6d473164ab
commit
6b41cf03a0
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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 () => {
|
||||
|
Loading…
Reference in New Issue
Block a user