mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-14 01:16:17 +02: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>,
|
res: Response<void>,
|
||||||
): Promise<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(
|
async bulkToggleFeaturesEnvironmentOff(
|
||||||
@ -735,7 +748,20 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
>,
|
>,
|
||||||
res: Response<void>,
|
res: Response<void>,
|
||||||
): Promise<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(
|
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(
|
async updateEnabled(
|
||||||
project: string,
|
project: string,
|
||||||
featureName: string,
|
featureName: string,
|
||||||
|
@ -413,14 +413,28 @@ test('Can bulk enable/disable environment for feature with strategies', async ()
|
|||||||
)
|
)
|
||||||
.send({ features: [featureName] })
|
.send({ features: [featureName] })
|
||||||
.set('Content-Type', 'application/json')
|
.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
|
await app.request
|
||||||
.post(
|
.post(
|
||||||
`/api/admin/projects/${project}/bulk_features/environments/${envName}/off`,
|
`/api/admin/projects/${project}/bulk_features/environments/${envName}/off`,
|
||||||
)
|
)
|
||||||
.send({ features: [featureName] })
|
.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 () => {
|
test("Trying to get a project that doesn't exist yields 404", async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user