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>
import { mapState, mapActions } from 'vuex';
import { __ } from '~/locale';
import Flash from '~/flash';
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import eventHub from '~/sidebar/event_hub';
import EditForm from './edit_form.vue';
import recaptchaModalImplementor from '~/vue_shared/mixins/recaptcha_modal_implementor';
export default {
components: {
......@@ -16,7 +14,6 @@ export default {
directives: {
tooltip,
},
mixins: [recaptchaModalImplementor],
props: {
fullPath: {
required: true,
......@@ -46,11 +43,9 @@ export default {
},
},
created() {
eventHub.$on('updateConfidentialAttribute', this.updateConfidentialAttribute);
eventHub.$on('closeConfidentialityForm', this.toggleForm);
},
beforeDestroy() {
eventHub.$off('updateConfidentialAttribute', this.updateConfidentialAttribute);
eventHub.$off('closeConfidentialityForm', this.toggleForm);
},
methods: {
......@@ -58,24 +53,6 @@ export default {
toggleForm() {
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>
......@@ -124,7 +101,5 @@ export default {
{{ __('This issue is confidential') }}
</div>
</div>
<recaptcha-modal v-if="showRecaptcha" :html="recaptchaHTML" @close="closeRecaptcha" />
</div>
</template>
......@@ -3,7 +3,6 @@ import $ from 'jquery';
import { GlLoadingIcon } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex';
import { __ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import Flash from '~/flash';
import eventHub from '../../event_hub';
......@@ -11,7 +10,6 @@ export default {
components: {
GlLoadingIcon,
},
mixins: [glFeatureFlagsMixin()],
props: {
fullPath: {
required: true,
......@@ -43,18 +41,14 @@ export default {
this.isLoading = true;
const confidential = !this.confidential;
if (this.glFeatures.confidentialApolloSidebar) {
this.updateConfidentialityOnIssue({ confidential, fullPath: this.fullPath })
.catch(() => {
Flash(__('Something went wrong trying to change the confidentiality of this issue'));
})
.finally(() => {
this.closeForm();
this.isLoading = false;
});
} else {
eventHub.$emit('updateConfidentialAttribute');
}
this.updateConfidentialityOnIssue({ confidential, fullPath: this.fullPath })
.catch(() => {
Flash(__('Something went wrong trying to change the confidentiality of this issue'));
})
.finally(() => {
this.closeForm();
this.isLoading = false;
});
},
},
};
......
......@@ -52,7 +52,6 @@ class Projects::IssuesController < Projects::ApplicationController
before_action only: :show do
push_frontend_feature_flag(:real_time_issue_sidebar, @project)
push_frontend_feature_flag(:confidential_apollo_sidebar, @project)
end
before_action only: :index do
......
......@@ -49,8 +49,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i
</div>
</div>
<!---->
</div>
`;
......@@ -111,8 +109,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = false and i
</div>
</div>
<!---->
</div>
`;
......@@ -164,8 +160,6 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is
</div>
</div>
<!---->
</div>
`;
......@@ -225,7 +219,5 @@ exports[`Confidential Issue Sidebar Block renders for confidential = true and is
</div>
</div>
<!---->
</div>
`;
......@@ -14,12 +14,7 @@ describe('Edit Form Buttons', () => {
let store;
const findConfidentialToggle = () => wrapper.find('[data-testid="confidential-toggle"]');
const createComponent = ({
props = {},
data = {},
confidentialApolloSidebar = false,
resolved = true,
}) => {
const createComponent = ({ props = {}, data = {}, resolved = true }) => {
store = createStore();
if (resolved) {
jest.spyOn(store, 'dispatch').mockResolvedValue();
......@@ -38,11 +33,6 @@ describe('Edit Form Buttons', () => {
...data,
};
},
provide: {
glFeatures: {
confidentialApolloSidebar,
},
},
store,
});
};
......@@ -98,62 +88,49 @@ describe('Edit Form Buttons', () => {
it('renders on or off text based on confidentiality', () => {
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', () => {
const isConfidential = true;
describe('when succeeds', () => {
beforeEach(() => {
createComponent({ data: { isLoading: false }, confidentialApolloSidebar: true });
wrapper.vm.$store.state.noteableData.confidential = isConfidential;
findConfidentialToggle().trigger('click');
});
describe('when succeeds', () => {
beforeEach(() => {
createComponent({ data: { isLoading: false } });
wrapper.vm.$store.state.noteableData.confidential = true;
findConfidentialToggle().trigger('click');
});
it('dispatches the correct action', () => {
expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssue', {
confidential: !isConfidential,
fullPath: '',
});
it('dispatches the correct action', () => {
expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssue', {
confidential: false,
fullPath: '',
});
});
it('resets loading', () => {
return waitForPromises().then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
});
it('resets loading', () => {
return waitForPromises().then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
});
});
it('emits close form', () => {
return waitForPromises().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm');
});
it('emits close form', () => {
return waitForPromises().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm');
});
});
});
describe('when fails', () => {
beforeEach(() => {
createComponent({
data: { isLoading: false },
confidentialApolloSidebar: true,
resolved: false,
});
wrapper.vm.$store.state.noteableData.confidential = isConfidential;
findConfidentialToggle().trigger('click');
describe('when fails', () => {
beforeEach(() => {
createComponent({
data: { isLoading: false },
resolved: false,
});
wrapper.vm.$store.state.noteableData.confidential = true;
findConfidentialToggle().trigger('click');
});
it('calls flash with the correct message', () => {
expect(flash).toHaveBeenCalledWith(
'Something went wrong trying to change the confidentiality of this issue',
);
});
it('calls flash with the correct message', () => {
expect(flash).toHaveBeenCalledWith(
'Something went wrong trying to change the confidentiality of this issue',
);
});
});
});
......@@ -3,11 +3,8 @@ import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
import EditForm from '~/sidebar/components/confidential/edit_form.vue';
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 { useMockLocationHelper } from 'helpers/mock_window_location_helper';
import eventHub from '~/sidebar/event_hub';
jest.mock('~/flash');
jest.mock('~/sidebar/services/sidebar_service');
......@@ -20,22 +17,6 @@ describe('Confidential Issue Sidebar Block', () => {
.fn()
.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 store = createStore();
const service = new SidebarService();
......@@ -133,61 +114,5 @@ describe('Confidential Issue Sidebar Block', () => {
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