Commit cead5255 authored by Mark Florian's avatar Mark Florian

Fix reloading of licenses in project settings

This was broken by an MR[1] which removed an enabled-by-default
`parsed_license_report` feature flag. That feature flag was
previously[2] used to branch in a place where it wasn't appropriate.

This MR restores the code branch, but changes the condition.

[1]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24007
[2]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19078
parent 4b909f29
......@@ -93,9 +93,18 @@ export const receiveLoadLicenseReportError = ({ commit }, error) => {
export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL);
};
export const receiveSetLicenseApproval = ({ commit, dispatch }) => {
export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => {
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');
} else {
dispatch('loadManagedLicenses');
}
};
export const receiveSetLicenseApprovalError = ({ commit }, error) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error);
......
......@@ -10,6 +10,7 @@ import axios from '~/lib/utils/axios_utils';
describe('License store actions', () => {
const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`;
const licensesApiPath = `${TEST_HOST}/licensesApiPath`;
let axiosMock;
let licenseId;
......@@ -177,11 +178,12 @@ describe('License store actions', () => {
});
describe('receiveSetLicenseApproval', () => {
describe('given the licensesApiPath is provided', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadParsedLicenseReport', done => {
testAction(
actions.receiveSetLicenseApproval,
null,
state,
{ ...state, licensesApiPath },
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadParsedLicenseReport' }],
)
......@@ -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', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL_ERROR', done => {
const error = new Error('Test');
......@@ -533,7 +550,6 @@ describe('License store actions', () => {
});
describe('loadParsedLicenseReport', () => {
const licensesApiPath = `${TEST_HOST}/licensesApiPath`;
let licensesApiMock;
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