Commit a7098dbb authored by Dave Pisek's avatar Dave Pisek

Fix link for commit-type security report items

This commit fixes an issue that happened on the pipeline security tab.

It prevented a correct link from showing when a GitLab instance was
installed under a relative URL.

Changelog: fixed
EE: true
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64565
parent 86e8013f
...@@ -23,6 +23,7 @@ export default () => { ...@@ -23,6 +23,7 @@ export default () => {
vulnerabilitiesEndpoint, vulnerabilitiesEndpoint,
emptyStateUnauthorizedSvgPath, emptyStateUnauthorizedSvgPath,
emptyStateForbiddenSvgPath, emptyStateForbiddenSvgPath,
projectCommitPath,
projectFullPath, projectFullPath,
pipelineJobsPath, pipelineJobsPath,
canAdminVulnerability, canAdminVulnerability,
...@@ -43,6 +44,7 @@ export default () => { ...@@ -43,6 +44,7 @@ export default () => {
provide: { provide: {
dashboardType: DASHBOARD_TYPES.PIPELINE, dashboardType: DASHBOARD_TYPES.PIPELINE,
projectId: parseInt(projectId, 10), projectId: parseInt(projectId, 10),
projectCommitPath,
projectFullPath, projectFullPath,
dashboardDocumentation, dashboardDocumentation,
emptyStateSvgPath, emptyStateSvgPath,
......
<script> <script>
import { GlLink } from '@gitlab/ui'; import { GlLink } from '@gitlab/ui';
import { isRootRelative } from '~/lib/utils/url_utility';
export default { export default {
components: { components: {
GlLink, GlLink,
}, },
inject: ['projectFullPath'], inject: ['projectCommitPath'],
props: { props: {
value: { value: {
type: String, type: String,
...@@ -14,20 +13,13 @@ export default { ...@@ -14,20 +13,13 @@ export default {
}, },
}, },
computed: { computed: {
commitPath() { linkToCommit() {
const { projectFullPath, value } = this; return `${this.projectCommitPath}/${this.value}`;
// `projectFullPath` comes in two flavors: relative (e.g.: `group/project`) and absolute (e.g.: `/group/project`)
// adding a leading slash to the relative path makes sure we always link to an absolute path
const absoluteProjectPath = isRootRelative(projectFullPath)
? projectFullPath
: `/${projectFullPath}`;
return `${absoluteProjectPath}/-/commit/${value}`;
}, },
}, },
}; };
</script> </script>
<template> <template>
<gl-link :href="commitPath">{{ value }}</gl-link> <gl-link :href="linkToCommit">{{ value }}</gl-link>
</template> </template>
...@@ -8,7 +8,9 @@ export default (el) => { ...@@ -8,7 +8,9 @@ export default (el) => {
return null; return null;
} }
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability), { const { vulnerability: rawVulnerability, projectCommitPath } = el.dataset;
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(rawVulnerability), {
deep: true, deep: true,
}); });
...@@ -18,6 +20,7 @@ export default (el) => { ...@@ -18,6 +20,7 @@ export default (el) => {
provide: { provide: {
reportType: vulnerability.reportType, reportType: vulnerability.reportType,
newIssueUrl: vulnerability.newIssueUrl, newIssueUrl: vulnerability.newIssueUrl,
projectCommitPath,
projectFingerprint: vulnerability.projectFingerprint, projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath, projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id, vulnerabilityId: vulnerability.id,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
empty_state_unauthorized_svg_path: image_path('illustrations/user-not-logged-in.svg'), empty_state_unauthorized_svg_path: image_path('illustrations/user-not-logged-in.svg'),
empty_state_forbidden_svg_path: image_path('illustrations/lock_promotion.svg'), empty_state_forbidden_svg_path: image_path('illustrations/lock_promotion.svg'),
project_full_path: project.path_with_namespace, project_full_path: project.path_with_namespace,
project_commit_path: "#{project_path(project)}/-/commit",
can_admin_vulnerability: can?(current_user, :admin_vulnerability, project).to_s, can_admin_vulnerability: can?(current_user, :admin_vulnerability, project).to_s,
security_report_help_page_link: help_page_path('user/application_security/index', anchor: 'security-report-validation') } } security_report_help_page_link: help_page_path('user/application_security/index', anchor: 'security-report-validation') } }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- breadcrumb_title @vulnerability.id - breadcrumb_title @vulnerability.id
- page_title @vulnerability.title - page_title @vulnerability.title
- page_description @vulnerability.description - page_description @vulnerability.description
- vulnerability_init_details = { vulnerability: vulnerability_details_json(@vulnerability, @pipeline)}
- add_page_specific_style 'page_bundles/security_dashboard' - add_page_specific_style 'page_bundles/security_dashboard'
#js-vulnerability-main{ data: vulnerability_init_details } #js-vulnerability-main{ data: { vulnerability: vulnerability_details_json(@vulnerability, @pipeline),
project_commit_path: "#{project_path(@vulnerability.project)}/-/commit" } }
...@@ -5,36 +5,33 @@ import Commit from 'ee/vulnerabilities/components/generic_report/types/commit.vu ...@@ -5,36 +5,33 @@ import Commit from 'ee/vulnerabilities/components/generic_report/types/commit.vu
const TEST_DATA = { const TEST_DATA = {
value: '24922148', value: '24922148',
}; };
const TEST_PROJECT_COMMIT_PATH = '/foo/bar';
describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () => { describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () => {
let wrapper; let wrapper;
const createWrapper = ({ provide } = {}) => { const createWrapper = () => {
return shallowMount(Commit, { return shallowMount(Commit, {
propsData: TEST_DATA, propsData: TEST_DATA,
provide: { provide: {
projectFullPath: '', projectCommitPath: TEST_PROJECT_COMMIT_PATH,
...provide,
}, },
}); });
}; };
const findLink = () => wrapper.findComponent(GlLink); const findLink = () => wrapper.findComponent(GlLink);
beforeEach(() => {
wrapper = createWrapper();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
it.each(['/foo/bar', 'foo/bar'])( it('links to the given commit hash', () => {
'given `projectFullPath` is "%s" it links to the absolute path of the commit', expect(findLink().attributes('href')).toBe(`${TEST_PROJECT_COMMIT_PATH}/${TEST_DATA.value}`);
(projectFullPath) => { });
const absoluteCommitPath = `/foo/bar/-/commit/${TEST_DATA.value}`;
wrapper = createWrapper({ provide: { projectFullPath } });
expect(findLink().attributes('href')).toBe(absoluteCommitPath);
},
);
it('shows the value as the link-text', () => { it('shows the value as the link-text', () => {
wrapper = createWrapper(); wrapper = createWrapper();
......
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