Commit 79b9bb18 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'use-feature-flags-plugin-ff-permissions' into 'master'

Use Feature Flags Plugin for FF Permissions

See merge request gitlab-org/gitlab!17541
parents b7e4d2e7 31a02ff7
...@@ -3,6 +3,7 @@ import Vue from 'vue'; ...@@ -3,6 +3,7 @@ import Vue from 'vue';
import _ from 'underscore'; import _ from 'underscore';
import { GlButton, GlBadge, GlTooltip, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlBadge, GlTooltip, GlTooltipDirective } from '@gitlab/ui';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import ToggleButton from '~/vue_shared/components/toggle_button.vue'; import ToggleButton from '~/vue_shared/components/toggle_button.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import EnvironmentsDropdown from './environments_dropdown.vue'; import EnvironmentsDropdown from './environments_dropdown.vue';
...@@ -28,6 +29,7 @@ export default { ...@@ -28,6 +29,7 @@ export default {
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
mixins: [featureFlagsMixin()],
props: { props: {
name: { name: {
type: String, type: String,
...@@ -98,7 +100,7 @@ export default { ...@@ -98,7 +100,7 @@ export default {
return !this.permissionsFlag || (this.formScopes || []).every(scope => scope.canUpdate); return !this.permissionsFlag || (this.formScopes || []).every(scope => scope.canUpdate);
}, },
permissionsFlag() { permissionsFlag() {
return gon && gon.features && gon.features.featureFlagPermissions; return this.glFeatures.featureFlagPermissions;
}, },
userIds() { userIds() {
...@@ -137,7 +139,7 @@ export default { ...@@ -137,7 +139,7 @@ export default {
* be used override the default scope options * be used override the default scope options
*/ */
createNewScope(overrides) { createNewScope(overrides) {
this.formScopes.push(createNewEnvironmentScope(overrides)); this.formScopes.push(createNewEnvironmentScope(overrides, this.permissionsFlag));
this.newScope = ''; this.newScope = '';
}, },
......
...@@ -4,6 +4,8 @@ import store from '../store/index'; ...@@ -4,6 +4,8 @@ import store from '../store/index';
import FeatureFlagForm from './form.vue'; import FeatureFlagForm from './form.vue';
import { createNewEnvironmentScope } from '../store/modules/helpers'; import { createNewEnvironmentScope } from '../store/modules/helpers';
import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const { mapState, mapActions } = createNamespacedHelpers('new'); const { mapState, mapActions } = createNamespacedHelpers('new');
export default { export default {
...@@ -11,6 +13,7 @@ export default { ...@@ -11,6 +13,7 @@ export default {
components: { components: {
FeatureFlagForm, FeatureFlagForm,
}, },
mixins: [featureFlagsMixin()],
props: { props: {
endpoint: { endpoint: {
type: String, type: String,
...@@ -29,10 +32,13 @@ export default { ...@@ -29,10 +32,13 @@ export default {
...mapState(['error']), ...mapState(['error']),
scopes() { scopes() {
return [ return [
createNewEnvironmentScope({ createNewEnvironmentScope(
environmentScope: '*', {
active: true, environmentScope: '*',
}), active: true,
},
this.glFeatures.featureFlagsPermissions,
),
]; ];
}, },
}, },
......
...@@ -106,7 +106,7 @@ export const mapFromScopesViewModel = params => { ...@@ -106,7 +106,7 @@ export const mapFromScopesViewModel = params => {
* property values will be used to override the default values. * property values will be used to override the default values.
* *
*/ */
export const createNewEnvironmentScope = (overrides = {}) => { export const createNewEnvironmentScope = (overrides = {}, featureFlagPermissions = false) => {
const defaultScope = { const defaultScope = {
environmentScope: '', environmentScope: '',
active: false, active: false,
...@@ -121,7 +121,7 @@ export const createNewEnvironmentScope = (overrides = {}) => { ...@@ -121,7 +121,7 @@ export const createNewEnvironmentScope = (overrides = {}) => {
...overrides, ...overrides,
}; };
if (gon && gon.features && gon.features.featureFlagPermissions) { if (featureFlagPermissions) {
newScope.canUpdate = true; newScope.canUpdate = true;
newScope.protected = false; newScope.protected = false;
} }
......
...@@ -206,5 +206,14 @@ describe('feature flags helpers spec', () => { ...@@ -206,5 +206,14 @@ describe('feature flags helpers spec', () => {
expect(actual).toEqual(expected); expect(actual).toEqual(expected);
}); });
it('sets canUpdate and protected when called with featureFlagPermissions=true', () => {
expect(createNewEnvironmentScope({}, true)).toEqual(
expect.objectContaining({
canUpdate: true,
protected: false,
}),
);
});
}); });
}); });
...@@ -25,18 +25,13 @@ describe('feature flag form', () => { ...@@ -25,18 +25,13 @@ describe('feature flag form', () => {
wrapper = mount(localVue.extend(Form), { wrapper = mount(localVue.extend(Form), {
localVue, localVue,
propsData: props, propsData: props,
provide: {
glFeatures: { featureFlagPermissions: true },
},
sync: false, sync: false,
}); });
}; };
beforeAll(() => {
gon.features = { featureFlagPermissions: true };
});
afterAll(() => {
gon.features = null;
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
......
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