Commit 76fe3249 authored by Dave Pisek's avatar Dave Pisek

Fix file-location report type on pipeline view

This commit fixes an issue which prevents the `file-location` generic
security report type to correctly render on the pipeline's security tab.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64278#
EE: true

WIP: Add specs
parent a371a131
import _ from 'lodash'; import _ from 'lodash';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; import {
parseIntPagination,
normalizeHeaders,
convertObjectPropsToCamelCase,
} from '~/lib/utils/common_utils';
import download from '~/lib/utils/downloader'; import download from '~/lib/utils/downloader';
import { s__, n__, sprintf } from '~/locale'; import { s__, n__, sprintf } from '~/locale';
import toast from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
...@@ -72,11 +76,16 @@ export const requestVulnerabilities = ({ commit }) => { ...@@ -72,11 +76,16 @@ export const requestVulnerabilities = ({ commit }) => {
export const receiveVulnerabilitiesSuccess = ({ commit }, { headers, data }) => { export const receiveVulnerabilitiesSuccess = ({ commit }, { headers, data }) => {
const normalizedHeaders = normalizeHeaders(headers); const normalizedHeaders = normalizeHeaders(headers);
const pageInfo = parseIntPagination(normalizedHeaders); const pageInfo = parseIntPagination(normalizedHeaders);
// Vulnerabilities on pipelines don't have IDs.
// We need to add dummy IDs here to avoid rendering issues.
const vulnerabilities = data.map((vulnerability) => ({ const vulnerabilities = data.map((vulnerability) => ({
...vulnerability, ...vulnerability,
// Vulnerabilities on pipelines don't have IDs.
// We need to add dummy IDs here to avoid rendering issues.
id: vulnerability.id || _.uniqueId('client_'), id: vulnerability.id || _.uniqueId('client_'),
// The generic report component expects all fields within `vulnerability.details` to be in camelCase
...(vulnerability.details && {
details: convertObjectPropsToCamelCase(vulnerability.details, { deep: true }),
}),
})); }));
commit(types.RECEIVE_VULNERABILITIES_SUCCESS, { pageInfo, vulnerabilities }); commit(types.RECEIVE_VULNERABILITIES_SUCCESS, { pageInfo, vulnerabilities });
......
...@@ -187,6 +187,22 @@ describe('vulnerabilities actions', () => { ...@@ -187,6 +187,22 @@ describe('vulnerabilities actions', () => {
}, },
]); ]);
}); });
it('should transform each details property to camelCase', () => {
const dataWithDetails = [{ id: '1', details: { prop_one: '1' } }];
return testAction(
actions.receiveVulnerabilitiesSuccess,
{ headers, data: dataWithDetails },
state,
[
{
type: types.RECEIVE_VULNERABILITIES_SUCCESS,
payload: { pageInfo, vulnerabilities: [{ id: '1', details: { propOne: '1' } }] },
},
],
);
});
}); });
describe('receiveVulnerabilitiesError', () => { describe('receiveVulnerabilitiesError', () => {
......
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