Commit 9a0eb667 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ss/rm-confidential-api-call' into 'master'

Remove ff for confidential apollo implementation

See merge request gitlab-org/gitlab!37838
parents af249673 16b4671d
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Flash from '~/flash';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import eventHub from '~/sidebar/event_hub'; import eventHub from '~/sidebar/event_hub';
import EditForm from './edit_form.vue'; import EditForm from './edit_form.vue';
import recaptchaModalImplementor from '~/vue_shared/mixins/recaptcha_modal_implementor';
export default { export default {
components: { components: {
...@@ -16,7 +14,6 @@ export default { ...@@ -16,7 +14,6 @@ export default {
directives: { directives: {
tooltip, tooltip,
}, },
mixins: [recaptchaModalImplementor],
props: { props: {
fullPath: { fullPath: {
required: true, required: true,
...@@ -46,11 +43,9 @@ export default { ...@@ -46,11 +43,9 @@ export default {
}, },
}, },
created() { created() {
eventHub.$on('updateConfidentialAttribute', this.updateConfidentialAttribute);
eventHub.$on('closeConfidentialityForm', this.toggleForm); eventHub.$on('closeConfidentialityForm', this.toggleForm);
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('updateConfidentialAttribute', this.updateConfidentialAttribute);
eventHub.$off('closeConfidentialityForm', this.toggleForm); eventHub.$off('closeConfidentialityForm', this.toggleForm);
}, },
methods: { methods: {
...@@ -58,24 +53,6 @@ export default { ...@@ -58,24 +53,6 @@ export default {
toggleForm() { toggleForm() {
this.edit = !this.edit; this.edit = !this.edit;
}, },
closeForm() {
this.edit = false;
},
updateConfidentialAttribute() {
// TODO: rm when FF is defaulted to on.
const confidential = !this.confidential;
this.service
.update('issue', { confidential })
.then(({ data }) => this.checkForSpam(data))
.then(() => window.location.reload())
.catch(error => {
if (error.name === 'SpamError') {
this.openRecaptcha();
} else {
Flash(__('Something went wrong trying to change the confidentiality of this issue'));
}
});
},
}, },
}; };
</script> </script>
...@@ -124,7 +101,5 @@ export default { ...@@ -124,7 +101,5 @@ export default {
{{ __('This issue is confidential') }} {{ __('This issue is confidential') }}
</div> </div>
</div> </div>
<recaptcha-modal v-if="showRecaptcha" :html="recaptchaHTML" @close="closeRecaptcha" />
</div> </div>
</template> </template>
...@@ -3,7 +3,6 @@ import $ from 'jquery'; ...@@ -3,7 +3,6 @@ import $ from 'jquery';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { __ } from '~/locale'; import { __ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import Flash from '~/flash'; import Flash from '~/flash';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
...@@ -11,7 +10,6 @@ export default { ...@@ -11,7 +10,6 @@ export default {
components: { components: {
GlLoadingIcon, GlLoadingIcon,
}, },
mixins: [glFeatureFlagsMixin()],
props: { props: {
fullPath: { fullPath: {
required: true, required: true,
...@@ -43,18 +41,14 @@ export default { ...@@ -43,18 +41,14 @@ export default {
this.isLoading = true; this.isLoading = true;
const confidential = !this.confidential; const confidential = !this.confidential;
if (this.glFeatures.confidentialApolloSidebar) { this.updateConfidentialityOnIssue({ confidential, fullPath: this.fullPath })
this.updateConfidentialityOnIssue({ confidential, fullPath: this.fullPath }) .catch(() => {
.catch(() => { Flash(__('Something went wrong trying to change the confidentiality of this issue'));
Flash(__('Something went wrong trying to change the confidentiality of this issue')); })
}) .finally(() => {
.finally(() => { this.closeForm();
this.closeForm(); this.isLoading = false;
this.isLoading = false; });
});
} else {
eventHub.$emit('updateConfidentialAttribute');
}
}, },
}, },
}; };
......
...@@ -52,7 +52,6 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -52,7 +52,6 @@ class Projects::IssuesController < Projects::ApplicationController
before_action only: :show do before_action only: :show do
push_frontend_feature_flag(:real_time_issue_sidebar, @project) push_frontend_feature_flag(:real_time_issue_sidebar, @project)
push_frontend_feature_flag(:confidential_apollo_sidebar, @project)
end end
before_action only: :index do before_action only: :index do
......
...@@ -49,8 +49,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i ...@@ -49,8 +49,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i
</div> </div>
</div> </div>
<!---->
</div> </div>
`; `;
...@@ -111,8 +109,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i ...@@ -111,8 +109,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i
</div> </div>
</div> </div>
<!---->
</div> </div>
`; `;
...@@ -164,8 +160,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is ...@@ -164,8 +160,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is
</div> </div>
</div> </div>
<!---->
</div> </div>
`; `;
...@@ -225,7 +219,5 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is ...@@ -225,7 +219,5 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is
</div> </div>
</div> </div>
<!---->
</div> </div>
`; `;
...@@ -14,12 +14,7 @@ describe('Edit Form Buttons', () => { ...@@ -14,12 +14,7 @@ describe('Edit Form Buttons', () => {
let store; let store;
const findConfidentialToggle = () => wrapper.find('[data-testid="confidential-toggle"]'); const findConfidentialToggle = () => wrapper.find('[data-testid="confidential-toggle"]');
const createComponent = ({ const createComponent = ({ props = {}, data = {}, resolved = true }) => {
props = {},
data = {},
confidentialApolloSidebar = false,
resolved = true,
}) => {
store = createStore(); store = createStore();
if (resolved) { if (resolved) {
jest.spyOn(store, 'dispatch').mockResolvedValue(); jest.spyOn(store, 'dispatch').mockResolvedValue();
...@@ -38,11 +33,6 @@ describe('Edit Form Buttons', () => { ...@@ -38,11 +33,6 @@ describe('Edit Form Buttons', () => {
...data, ...data,
}; };
}, },
provide: {
glFeatures: {
confidentialApolloSidebar,
},
},
store, store,
}); });
}; };
...@@ -98,62 +88,49 @@ describe('Edit Form Buttons', () => { ...@@ -98,62 +88,49 @@ describe('Edit Form Buttons', () => {
it('renders on or off text based on confidentiality', () => { it('renders on or off text based on confidentiality', () => {
expect(findConfidentialToggle().text()).toBe('Turn Off'); expect(findConfidentialToggle().text()).toBe('Turn Off');
}); });
describe('when clicking on the confidential toggle', () => {
it('emits updateConfidentialAttribute', () => {
findConfidentialToggle().trigger('click');
expect(eventHub.$emit).toHaveBeenCalledWith('updateConfidentialAttribute');
});
});
}); });
describe('when confidentialApolloSidebar is turned on', () => { describe('when succeeds', () => {
const isConfidential = true; beforeEach(() => {
createComponent({ data: { isLoading: false } });
describe('when succeeds', () => { wrapper.vm.$store.state.noteableData.confidential = true;
beforeEach(() => { findConfidentialToggle().trigger('click');
createComponent({ data: { isLoading: false }, confidentialApolloSidebar: true }); });
wrapper.vm.$store.state.noteableData.confidential = isConfidential;
findConfidentialToggle().trigger('click');
});
it('dispatches the correct action', () => { it('dispatches the correct action', () => {
expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssue', { expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssue', {
confidential: !isConfidential, confidential: false,
fullPath: '', fullPath: '',
});
}); });
});
it('resets loading', () => { it('resets loading', () => {
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
});
}); });
});
it('emits close form', () => { it('emits close form', () => {
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm'); expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm');
});
}); });
}); });
});
describe('when fails', () => { describe('when fails', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
data: { isLoading: false }, data: { isLoading: false },
confidentialApolloSidebar: true, resolved: false,
resolved: false,
});
wrapper.vm.$store.state.noteableData.confidential = isConfidential;
findConfidentialToggle().trigger('click');
}); });
wrapper.vm.$store.state.noteableData.confidential = true;
findConfidentialToggle().trigger('click');
});
it('calls flash with the correct message', () => { it('calls flash with the correct message', () => {
expect(flash).toHaveBeenCalledWith( expect(flash).toHaveBeenCalledWith(
'Something went wrong trying to change the confidentiality of this issue', 'Something went wrong trying to change the confidentiality of this issue',
); );
});
}); });
}); });
}); });
...@@ -3,11 +3,8 @@ import { mockTracking, triggerEvent } from 'helpers/tracking_helper'; ...@@ -3,11 +3,8 @@ import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue'; import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
import EditForm from '~/sidebar/components/confidential/edit_form.vue'; import EditForm from '~/sidebar/components/confidential/edit_form.vue';
import SidebarService from '~/sidebar/services/sidebar_service'; import SidebarService from '~/sidebar/services/sidebar_service';
import createFlash from '~/flash';
import RecaptchaModal from '~/vue_shared/components/recaptcha_modal.vue';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import { useMockLocationHelper } from 'helpers/mock_window_location_helper'; import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
import eventHub from '~/sidebar/event_hub';
jest.mock('~/flash'); jest.mock('~/flash');
jest.mock('~/sidebar/services/sidebar_service'); jest.mock('~/sidebar/services/sidebar_service');
...@@ -20,22 +17,6 @@ describe('Confidential Issue Sidebar Block', () => { ...@@ -20,22 +17,6 @@ describe('Confidential Issue Sidebar Block', () => {
.fn() .fn()
.mockResolvedValue({ data: { issueSetConfidential: { issue: { confidential: true } } } }); .mockResolvedValue({ data: { issueSetConfidential: { issue: { confidential: true } } } });
const findRecaptchaModal = () => wrapper.find(RecaptchaModal);
const triggerUpdateConfidentialAttribute = () => {
wrapper.setData({ edit: true });
return (
// wait for edit form to become visible
wrapper.vm
.$nextTick()
.then(() => {
eventHub.$emit('updateConfidentialAttribute');
})
// wait for reCAPTCHA modal to render
.then(() => wrapper.vm.$nextTick())
);
};
const createComponent = ({ propsData, data = {} }) => { const createComponent = ({ propsData, data = {} }) => {
const store = createStore(); const store = createStore();
const service = new SidebarService(); const service = new SidebarService();
...@@ -133,61 +114,5 @@ describe('Confidential Issue Sidebar Block', () => { ...@@ -133,61 +114,5 @@ describe('Confidential Issue Sidebar Block', () => {
property: 'confidentiality', property: 'confidentiality',
}); });
}); });
describe('for successful update', () => {
beforeEach(() => {
SidebarService.prototype.update.mockResolvedValue({ data: 'irrelevant' });
});
it('reloads the page', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(window.location.reload).toHaveBeenCalled();
}));
it('does not show an error message', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(createFlash).not.toHaveBeenCalled();
}));
});
describe('for update error', () => {
beforeEach(() => {
SidebarService.prototype.update.mockRejectedValue(new Error('updating failed!'));
});
it('does not reload the page', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(window.location.reload).not.toHaveBeenCalled();
}));
it('shows an error message', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(createFlash).toHaveBeenCalled();
}));
});
describe('for spam error', () => {
beforeEach(() => {
SidebarService.prototype.update.mockRejectedValue({ name: 'SpamError' });
});
it('does not reload the page', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(window.location.reload).not.toHaveBeenCalled();
}));
it('does not show an error message', () =>
triggerUpdateConfidentialAttribute().then(() => {
expect(createFlash).not.toHaveBeenCalled();
}));
it('shows a reCAPTCHA modal', () => {
expect(findRecaptchaModal().exists()).toBe(false);
return triggerUpdateConfidentialAttribute().then(() => {
expect(findRecaptchaModal().exists()).toBe(true);
});
});
});
}); });
}); });
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