Commit d99aaa0d authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Mayra Cabrera

Add backend route to reset integration

With a simple controller action that returns 200 OK.
Actual logic to be implemented separately.
parent f05c3228
...@@ -61,7 +61,13 @@ export default { ...@@ -61,7 +61,13 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['setOverride', 'setIsSaving', 'setIsTesting', 'setIsResetting']), ...mapActions([
'setOverride',
'setIsSaving',
'setIsTesting',
'setIsResetting',
'fetchResetIntegration',
]),
onSaveClick() { onSaveClick() {
this.setIsSaving(true); this.setIsSaving(true);
eventHub.$emit('saveIntegration'); eventHub.$emit('saveIntegration');
...@@ -70,7 +76,9 @@ export default { ...@@ -70,7 +76,9 @@ export default {
this.setIsTesting(true); this.setIsTesting(true);
eventHub.$emit('testIntegration'); eventHub.$emit('testIntegration');
}, },
onResetClick() {}, onResetClick() {
this.fetchResetIntegration();
},
}, },
}; };
</script> </script>
......
import axios from 'axios';
import { refreshCurrentPage } from '~/lib/utils/url_utility';
import * as types from './mutation_types'; import * as types from './mutation_types';
export const setOverride = ({ commit }, override) => commit(types.SET_OVERRIDE, override); export const setOverride = ({ commit }, override) => commit(types.SET_OVERRIDE, override);
...@@ -5,3 +7,22 @@ export const setIsSaving = ({ commit }, isSaving) => commit(types.SET_IS_SAVING, ...@@ -5,3 +7,22 @@ export const setIsSaving = ({ commit }, isSaving) => commit(types.SET_IS_SAVING,
export const setIsTesting = ({ commit }, isTesting) => commit(types.SET_IS_TESTING, isTesting); export const setIsTesting = ({ commit }, isTesting) => commit(types.SET_IS_TESTING, isTesting);
export const setIsResetting = ({ commit }, isResetting) => export const setIsResetting = ({ commit }, isResetting) =>
commit(types.SET_IS_RESETTING, isResetting); commit(types.SET_IS_RESETTING, isResetting);
export const requestResetIntegration = ({ commit }) => {
commit(types.REQUEST_RESET_INTEGRATION);
};
export const receiveResetIntegrationSuccess = () => {
refreshCurrentPage();
};
export const receiveResetIntegrationError = ({ commit }) => {
commit(types.RECEIVE_RESET_INTEGRATION_ERROR);
};
export const fetchResetIntegration = ({ dispatch, getters }) => {
dispatch('requestResetIntegration');
return axios
.post(getters.propsSource.resetPath, { params: { format: 'json' } })
.then(() => dispatch('receiveResetIntegrationSuccess'))
.catch(() => dispatch('receiveResetIntegrationError'));
};
...@@ -2,3 +2,6 @@ export const SET_OVERRIDE = 'SET_OVERRIDE'; ...@@ -2,3 +2,6 @@ export const SET_OVERRIDE = 'SET_OVERRIDE';
export const SET_IS_SAVING = 'SET_IS_SAVING'; export const SET_IS_SAVING = 'SET_IS_SAVING';
export const SET_IS_TESTING = 'SET_IS_TESTING'; export const SET_IS_TESTING = 'SET_IS_TESTING';
export const SET_IS_RESETTING = 'SET_IS_RESETTING'; export const SET_IS_RESETTING = 'SET_IS_RESETTING';
export const REQUEST_RESET_INTEGRATION = 'REQUEST_RESET_INTEGRATION';
export const RECEIVE_RESET_INTEGRATION_ERROR = 'RECEIVE_RESET_INTEGRATION_ERROR';
...@@ -13,4 +13,10 @@ export default { ...@@ -13,4 +13,10 @@ export default {
[types.SET_IS_RESETTING](state, isResetting) { [types.SET_IS_RESETTING](state, isResetting) {
state.isResetting = isResetting; state.isResetting = isResetting;
}, },
[types.REQUEST_RESET_INTEGRATION](state) {
state.isResetting = true;
},
[types.RECEIVE_RESET_INTEGRATION_ERROR](state) {
state.isResetting = false;
},
}; };
...@@ -43,6 +43,12 @@ module IntegrationsActions ...@@ -43,6 +43,12 @@ module IntegrationsActions
render json: {}, status: :ok render json: {}, status: :ok
end end
def reset
flash[:notice] = s_('Integrations|This integration, and inheriting projects were reset.')
render json: {}, status: :ok
end
private private
def integrations_enabled? def integrations_enabled?
......
...@@ -75,7 +75,15 @@ module ServicesHelper ...@@ -75,7 +75,15 @@ module ServicesHelper
end end
end end
def integration_form_data(integration) def scoped_reset_integration_path(integration, group: nil)
if group.present?
reset_group_settings_integration_path(group, integration)
else
reset_admin_application_settings_integration_path(integration)
end
end
def integration_form_data(integration, group: nil)
{ {
id: integration.id, id: integration.id,
show_active: integration.show_active_box?.to_s, show_active: integration.show_active_box?.to_s,
...@@ -94,7 +102,7 @@ module ServicesHelper ...@@ -94,7 +102,7 @@ module ServicesHelper
cancel_path: scoped_integrations_path, cancel_path: scoped_integrations_path,
can_test: integration.can_test?.to_s, can_test: integration.can_test?.to_s,
test_path: scoped_test_integration_path(integration), test_path: scoped_test_integration_path(integration),
reset_path: '' reset_path: reset_integrations?(group: group) ? scoped_reset_integration_path(integration, group: group) : ''
} }
end end
...@@ -122,6 +130,10 @@ module ServicesHelper ...@@ -122,6 +130,10 @@ module ServicesHelper
!Gitlab.com? !Gitlab.com?
end end
def reset_integrations?(group: nil)
Feature.enabled?(:reset_integrations, group, type: :development)
end
extend self extend self
private private
......
...@@ -9,5 +9,5 @@ ...@@ -9,5 +9,5 @@
.service-settings .service-settings
- if @default_integration - if @default_integration
.js-vue-default-integration-settings{ data: integration_form_data(@default_integration) } .js-vue-default-integration-settings{ data: integration_form_data(@default_integration, group: @group) }
.js-vue-integration-settings{ data: integration_form_data(integration) } .js-vue-integration-settings{ data: integration_form_data(integration, group: @group) }
---
name: reset_integrations
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47546
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/283875
milestone: '13.7'
type: development
group: group::ecosystem
default_enabled: false
...@@ -126,6 +126,7 @@ namespace :admin do ...@@ -126,6 +126,7 @@ namespace :admin do
resources :integrations, only: [:edit, :update] do resources :integrations, only: [:edit, :update] do
member do member do
put :test put :test
post :reset
end end
end end
......
...@@ -46,6 +46,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -46,6 +46,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
resources :integrations, only: [:index, :edit, :update] do resources :integrations, only: [:index, :edit, :update] do
member do member do
put :test put :test
post :reset
end end
end end
end end
......
...@@ -10,7 +10,7 @@ module EE ...@@ -10,7 +10,7 @@ module EE
end end
override :integration_form_data override :integration_form_data
def integration_form_data(integration) def integration_form_data(integration, group: nil)
form_data = super form_data = super
if integration.is_a?(JiraService) if integration.is_a?(JiraService)
......
...@@ -14792,6 +14792,9 @@ msgstr "" ...@@ -14792,6 +14792,9 @@ msgstr ""
msgid "Integrations|Standard" msgid "Integrations|Standard"
msgstr "" msgstr ""
msgid "Integrations|This integration, and inheriting projects were reset."
msgstr ""
msgid "Integrations|To keep this project going, create a new issue." msgid "Integrations|To keep this project going, create a new issue."
msgstr "" msgstr ""
......
...@@ -73,4 +73,20 @@ RSpec.describe Admin::IntegrationsController do ...@@ -73,4 +73,20 @@ RSpec.describe Admin::IntegrationsController do
end end
end end
end end
describe '#reset' do
let(:integration) { create(:jira_service, :instance) }
before do
post :reset, params: { id: integration.class.to_param }
end
it 'returns 200 OK' do
expected_json = {}.to_json
expect(flash[:notice]).to eq('This integration, and inheriting projects were reset.')
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).to eq(expected_json)
end
end
end end
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { refreshCurrentPage } from '~/lib/utils/url_utility';
import createState from '~/integrations/edit/store/state'; import createState from '~/integrations/edit/store/state';
import { import {
setOverride, setOverride,
setIsSaving, setIsSaving,
setIsTesting, setIsTesting,
setIsResetting, setIsResetting,
requestResetIntegration,
receiveResetIntegrationSuccess,
receiveResetIntegrationError,
} from '~/integrations/edit/store/actions'; } from '~/integrations/edit/store/actions';
import * as types from '~/integrations/edit/store/mutation_types'; import * as types from '~/integrations/edit/store/mutation_types';
jest.mock('~/lib/utils/url_utility');
describe('Integration form store actions', () => { describe('Integration form store actions', () => {
let state; let state;
...@@ -40,4 +46,28 @@ describe('Integration form store actions', () => { ...@@ -40,4 +46,28 @@ describe('Integration form store actions', () => {
]); ]);
}); });
}); });
describe('requestResetIntegration', () => {
it('should commit REQUEST_RESET_INTEGRATION mutation', () => {
return testAction(requestResetIntegration, null, state, [
{ type: types.REQUEST_RESET_INTEGRATION },
]);
});
});
describe('receiveResetIntegrationSuccess', () => {
it('should call refreshCurrentPage()', () => {
return testAction(receiveResetIntegrationSuccess, null, state, [], [], () => {
expect(refreshCurrentPage).toHaveBeenCalled();
});
});
});
describe('receiveResetIntegrationError', () => {
it('should commit RECEIVE_RESET_INTEGRATION_ERROR mutation', () => {
return testAction(receiveResetIntegrationError, null, state, [
{ type: types.RECEIVE_RESET_INTEGRATION_ERROR },
]);
});
});
}); });
...@@ -40,4 +40,20 @@ describe('Integration form store mutations', () => { ...@@ -40,4 +40,20 @@ describe('Integration form store mutations', () => {
expect(state.isResetting).toBe(true); expect(state.isResetting).toBe(true);
}); });
}); });
describe(`${types.REQUEST_RESET_INTEGRATION}`, () => {
it('sets isResetting', () => {
mutations[types.REQUEST_RESET_INTEGRATION](state);
expect(state.isResetting).toBe(true);
});
});
describe(`${types.RECEIVE_RESET_INTEGRATION_ERROR}`, () => {
it('sets isResetting', () => {
mutations[types.RECEIVE_RESET_INTEGRATION_ERROR](state);
expect(state.isResetting).toBe(false);
});
});
}); });
...@@ -59,4 +59,57 @@ RSpec.describe ServicesHelper do ...@@ -59,4 +59,57 @@ RSpec.describe ServicesHelper do
end end
end end
end end
describe '#scoped_reset_integration_path' do
let(:integration) { build_stubbed(:jira_service) }
let(:group) { nil }
subject { helper.scoped_reset_integration_path(integration, group: group) }
context 'when no group is present' do
it 'returns instance-level path' do
is_expected.to eq(reset_admin_application_settings_integration_path(integration))
end
end
context 'when group is present' do
let(:group) { build_stubbed(:group) }
it 'returns group-level path' do
is_expected.to eq(reset_group_settings_integration_path(group, integration))
end
end
end
describe '#reset_integrations?' do
let(:group) { nil }
subject { helper.reset_integrations?(group: group) }
context 'when `reset_integrations` is not enabled' do
it 'returns false' do
stub_feature_flags(reset_integrations: false)
is_expected.to eq(false)
end
end
context 'when `reset_integrations` is enabled' do
it 'returns true' do
stub_feature_flags(reset_integrations: true)
is_expected.to eq(true)
end
end
context 'when `reset_integrations` is enabled for a group' do
let(:group) { build_stubbed(:group) }
it 'returns true' do
stub_feature_flags(reset_integrations: group)
is_expected.to eq(true)
end
end
end
end end
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