1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00

fix: bypass change requests when unprotected deleting (#3720)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-05-09 14:18:21 +03:00 committed by GitHub
parent 4bb7ce7761
commit 5229c44dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 164 additions and 1 deletions

View File

@ -661,7 +661,7 @@ class FeatureToggleService {
if (hasOnlyDisabledStrategies) {
// Disable the feature in the environment if it only has disabled strategies
await this.updateEnabled(
await this.unprotectedUpdateEnabled(
projectId,
featureName,
environment,

View File

@ -2925,3 +2925,166 @@ test('should disable strategies in place', async () => {
expect(updatedStrategies[0].id).toBe(updatedStrategyOne.id);
expect(updatedStrategies[0].disabled).toBe(updatedStrategyOne.disabled);
});
test('Disabling last strategy for feature environment should disable that environment', async () => {
const envName = 'last_strategy_disable_env';
const featureName = 'last_strategy_disable_feature';
// Create environment
await db.stores.environmentStore.create({
name: envName,
type: 'test',
});
// Connect environment to project
await app.request
.post('/api/admin/projects/default/environments')
.send({
environment: envName,
})
.expect(200);
await app.request
.post('/api/admin/projects/default/features')
.send({ name: featureName })
.expect(201);
let strategyId;
await app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/strategies`,
)
.send({
name: 'default',
parameters: {
userId: 'string',
},
})
.expect(200)
.expect((res) => {
strategyId = res.body.id;
});
// Enable feature_environment
await app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/on`,
)
.send({})
.expect(200);
await app.request
.get(
`/api/admin/projects/default/features/${featureName}/environments/${envName}`,
)
.expect(200)
.expect((res) => {
expect(res.body.enabled).toBeTruthy();
});
// Disable last strategy, this should also disable the environment
await app.request
.patch(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/strategies/${strategyId}`,
)
.send([
{
path: '/disabled',
value: true,
op: 'replace',
},
])
.expect(200);
await app.request
.get(
`/api/admin/projects/default/features/${featureName}/environments/${envName}`,
)
.expect(200)
.expect((res) => {
expect(res.body.enabled).toBeFalsy();
});
});
test('Enabling a feature environment should add the default strategy when only disabled strategies', async () => {
const envName = 'add_default_strategy';
const featureName = 'add_default_strategy_feature';
// Create environment
await db.stores.environmentStore.create({
name: envName,
type: 'test',
});
// Connect environment to project
await app.request
.post('/api/admin/projects/default/environments')
.send({
environment: envName,
})
.expect(200);
await app.request
.post('/api/admin/projects/default/features')
.send({ name: featureName })
.expect(201);
let strategyId;
await app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/strategies`,
)
.send({
name: 'default',
parameters: {
userId: 'string',
},
})
.expect(200)
.expect((res) => {
strategyId = res.body.id;
});
// Enable feature_environment
await app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/on`,
)
.send({})
.expect(200);
await app.request
.get(
`/api/admin/projects/default/features/${featureName}/environments/${envName}`,
)
.expect(200)
.expect((res) => {
expect(res.body.enabled).toBeTruthy();
});
// Disable last strategy, this should also disable the environment
await app.request
.patch(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/strategies/${strategyId}`,
)
.send([
{
path: '/disabled',
value: true,
op: 'replace',
},
])
.expect(200);
await app.request
.get(
`/api/admin/projects/default/features/${featureName}/environments/${envName}`,
)
.expect(200)
.expect((res) => {
expect(res.body.enabled).toBeFalsy();
});
// Enable feature_environment
await app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/${envName}/on`,
)
.send({})
.expect(200);
await app.request
.get(
`/api/admin/projects/default/features/${featureName}/environments/${envName}`,
)
.expect(200)
.expect((res) => {
expect(res.body.enabled).toBeTruthy();
expect(res.body.strategies.length).toBe(2);
expect(res.body.strategies[0].disabled).toBeTruthy();
expect(res.body.strategies[1].disabled).toBeFalsy();
});
});