Commit ae5d83de authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '195992-fix-license-compliance-ee' into 'master'

Fix reloading of licenses in project settings

Closes #195992

See merge request gitlab-org/gitlab!24361
parents 84bf6584 cead5255
...@@ -93,9 +93,18 @@ export const receiveLoadLicenseReportError = ({ commit }, error) => { ...@@ -93,9 +93,18 @@ export const receiveLoadLicenseReportError = ({ commit }, error) => {
export const requestSetLicenseApproval = ({ commit }) => { export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL); commit(types.REQUEST_SET_LICENSE_APPROVAL);
}; };
export const receiveSetLicenseApproval = ({ commit, dispatch }) => { export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL); commit(types.RECEIVE_SET_LICENSE_APPROVAL);
// If we have the licenses API endpoint, fetch from there. This corresponds
// to the cases that we're viewing the merge request or pipeline pages.
// Otherwise, fetch from the managed licenses endpoint, which corresponds to
// the project settings page.
// https://gitlab.com/gitlab-org/gitlab/issues/201867
if (state.licensesApiPath) {
dispatch('loadParsedLicenseReport'); dispatch('loadParsedLicenseReport');
} else {
dispatch('loadManagedLicenses');
}
}; };
export const receiveSetLicenseApprovalError = ({ commit }, error) => { export const receiveSetLicenseApprovalError = ({ commit }, error) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error); commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error);
......
...@@ -10,6 +10,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -10,6 +10,7 @@ import axios from '~/lib/utils/axios_utils';
describe('License store actions', () => { describe('License store actions', () => {
const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`; const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`;
const licensesApiPath = `${TEST_HOST}/licensesApiPath`;
let axiosMock; let axiosMock;
let licenseId; let licenseId;
...@@ -177,11 +178,12 @@ describe('License store actions', () => { ...@@ -177,11 +178,12 @@ describe('License store actions', () => {
}); });
describe('receiveSetLicenseApproval', () => { describe('receiveSetLicenseApproval', () => {
describe('given the licensesApiPath is provided', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadParsedLicenseReport', done => { it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadParsedLicenseReport', done => {
testAction( testAction(
actions.receiveSetLicenseApproval, actions.receiveSetLicenseApproval,
null, null,
state, { ...state, licensesApiPath },
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }], [{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadParsedLicenseReport' }], [{ type: 'loadParsedLicenseReport' }],
) )
...@@ -190,6 +192,21 @@ describe('License store actions', () => { ...@@ -190,6 +192,21 @@ describe('License store actions', () => {
}); });
}); });
describe('given the licensesApiPath is not provided', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadManagedLicenses', done => {
testAction(
actions.receiveSetLicenseApproval,
null,
state,
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadManagedLicenses' }],
)
.then(done)
.catch(done.fail);
});
});
});
describe('receiveSetLicenseApprovalError', () => { describe('receiveSetLicenseApprovalError', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL_ERROR', done => { it('commits RECEIVE_SET_LICENSE_APPROVAL_ERROR', done => {
const error = new Error('Test'); const error = new Error('Test');
...@@ -533,7 +550,6 @@ describe('License store actions', () => { ...@@ -533,7 +550,6 @@ describe('License store actions', () => {
}); });
describe('loadParsedLicenseReport', () => { describe('loadParsedLicenseReport', () => {
const licensesApiPath = `${TEST_HOST}/licensesApiPath`;
let licensesApiMock; let licensesApiMock;
let rawLicenseReport; let rawLicenseReport;
......
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