Commit b06e1d67 authored by Andrew Fontaine's avatar Andrew Fontaine

Ensure User IDs are Removed When Moving to Default

If All Users is selected, the user IDs should not be saved.
parent bc9dd91f
...@@ -202,6 +202,12 @@ export default { ...@@ -202,6 +202,12 @@ export default {
shouldDisplayUserIds(scope) { shouldDisplayUserIds(scope) {
return scope.rolloutStrategy === ROLLOUT_STRATEGY_USER_ID || scope.shouldIncludeUserIds; return scope.rolloutStrategy === ROLLOUT_STRATEGY_USER_ID || scope.shouldIncludeUserIds;
}, },
onStrategyChange(index) {
const scope = this.filteredScopes[index];
scope.shouldIncludeUserIds =
scope.rolloutUserIds.length > 0 &&
scope.rolloutStrategy === ROLLOUT_STRATEGY_PERCENT_ROLLOUT;
},
}, },
}; };
</script> </script>
...@@ -256,6 +262,7 @@ export default { ...@@ -256,6 +262,7 @@ export default {
<div <div
v-for="(scope, index) in filteredScopes" v-for="(scope, index) in filteredScopes"
:key="scope.id" :key="scope.id"
ref="scopeRow"
class="gl-responsive-table-row" class="gl-responsive-table-row"
role="row" role="row"
> >
...@@ -281,9 +288,9 @@ export default { ...@@ -281,9 +288,9 @@ export default {
@clearInput="env => (scope.environmentScope = '')" @clearInput="env => (scope.environmentScope = '')"
/> />
<gl-badge v-if="permissionsFlag && scope.protected" variant="success">{{ <gl-badge v-if="permissionsFlag && scope.protected" variant="success">
s__('FeatureFlags|Protected') {{ s__('FeatureFlags|Protected') }}
}}</gl-badge> </gl-badge>
</div> </div>
</div> </div>
...@@ -314,6 +321,7 @@ export default { ...@@ -314,6 +321,7 @@ export default {
v-model="scope.rolloutStrategy" v-model="scope.rolloutStrategy"
:disabled="!scope.active" :disabled="!scope.active"
class="form-control select-control w-100 js-rollout-strategy" class="form-control select-control w-100 js-rollout-strategy"
@change="onStrategyChange(index)"
> >
<option :value="$options.ROLLOUT_STRATEGY_ALL_USERS"> <option :value="$options.ROLLOUT_STRATEGY_ALL_USERS">
{{ s__('FeatureFlags|All users') }} {{ s__('FeatureFlags|All users') }}
...@@ -433,9 +441,9 @@ export default { ...@@ -433,9 +441,9 @@ export default {
{{ s__('FeatureFlags|Rollout Strategy') }} {{ s__('FeatureFlags|Rollout Strategy') }}
</div> </div>
<div class="table-mobile-content js-rollout-strategy form-inline"> <div class="table-mobile-content js-rollout-strategy form-inline">
<label class="sr-only" for="new-rollout-strategy-placeholder"> <label class="sr-only" for="new-rollout-strategy-placeholder">{{
{{ s__('FeatureFlags|Rollout Strategy') }} s__('FeatureFlags|Rollout Strategy')
</label> }}</label>
<div class="select-wrapper col-12 col-md-8 p-0"> <div class="select-wrapper col-12 col-md-8 p-0">
<select <select
id="new-rollout-strategy-placeholder" id="new-rollout-strategy-placeholder"
......
...@@ -49,7 +49,7 @@ export const mapToScopesViewModel = scopesFromRails => ...@@ -49,7 +49,7 @@ export const mapToScopesViewModel = scopesFromRails =>
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
shouldBeDestroyed: Boolean(s._destroy), shouldBeDestroyed: Boolean(s._destroy),
shouldIncludeUserIds: rolloutUserIds.length > 0, shouldIncludeUserIds: rolloutUserIds.length > 0 && percentStrategy !== null,
}; };
}); });
/** /**
......
---
title: Ensure User IDs are Removed When Moving to All Users Strategy
merge_request: 25190
author:
type: fixed
...@@ -14,29 +14,18 @@ import { featureFlag } from '../mock_data'; ...@@ -14,29 +14,18 @@ import { featureFlag } from '../mock_data';
describe('feature flag form', () => { describe('feature flag form', () => {
let wrapper; let wrapper;
let oldGon;
const requiredProps = { const requiredProps = {
cancelPath: 'feature_flags', cancelPath: 'feature_flags',
submitText: 'Create', submitText: 'Create',
environmentsEndpoint: '/environments.json', environmentsEndpoint: '/environments.json',
}; };
beforeEach(() => {
oldGon = window.gon;
window.gon = { features: { featureFlagsUsersPerEnvironment: true } };
});
afterEach(() => {
window.gon = oldGon;
});
const factory = (props = {}) => { const factory = (props = {}) => {
wrapper = shallowMount(Form, { wrapper = shallowMount(Form, {
propsData: props, propsData: props,
provide: { provide: {
glFeatures: { glFeatures: {
featureFlagPermissions: true, featureFlagPermissions: true,
featureFlagsUsersPerEnvironment: true,
}, },
}, },
}); });
...@@ -174,6 +163,15 @@ describe('feature flag form', () => { ...@@ -174,6 +163,15 @@ describe('feature flag form', () => {
}); });
}); });
}); });
describe('on strategy change', () => {
it('should not include user IDs if All Users is selected', () => {
const scope = wrapper.find({ ref: 'scopeRow' });
scope.find('select').setValue(ROLLOUT_STRATEGY_ALL_USERS);
return wrapper.vm.$nextTick().then(() => {
expect(scope.find('#rollout-user-id-0').exists()).toBe(false);
});
});
});
}); });
describe('deleting an existing scope', () => { describe('deleting an existing scope', () => {
...@@ -354,6 +352,7 @@ describe('feature flag form', () => { ...@@ -354,6 +352,7 @@ describe('feature flag form', () => {
rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
rolloutPercentage: '55', rolloutPercentage: '55',
rolloutUserIds: '', rolloutUserIds: '',
shouldIncludeUserIds: false,
}, },
{ {
id: expect.any(String), id: expect.any(String),
...@@ -374,6 +373,7 @@ describe('feature flag form', () => { ...@@ -374,6 +373,7 @@ describe('feature flag form', () => {
rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT, rolloutStrategy: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
rolloutPercentage: DEFAULT_PERCENT_ROLLOUT, rolloutPercentage: DEFAULT_PERCENT_ROLLOUT,
rolloutUserIds: '', rolloutUserIds: '',
shouldIncludeUserIds: false,
}, },
]); ]);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment