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 () => {
vulnerabilitiesEndpoint,
emptyStateUnauthorizedSvgPath,
emptyStateForbiddenSvgPath,
projectCommitPath,
projectFullPath,
pipelineJobsPath,
canAdminVulnerability,
......@@ -43,6 +44,7 @@ export default () => {
provide: {
dashboardType: DASHBOARD_TYPES.PIPELINE,
projectId: parseInt(projectId, 10),
projectCommitPath,
projectFullPath,
dashboardDocumentation,
emptyStateSvgPath,
......
<script>
import { GlLink } from '@gitlab/ui';
import { isRootRelative } from '~/lib/utils/url_utility';
export default {
components: {
GlLink,
},
inject: ['projectFullPath'],
inject: ['projectCommitPath'],
props: {
value: {
type: String,
......@@ -14,20 +13,13 @@ export default {
},
},
computed: {
commitPath() {
const { projectFullPath, value } = this;
// `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}`;
linkToCommit() {
return `${this.projectCommitPath}/${this.value}`;
},
},
};
</script>
<template>
<gl-link :href="commitPath">{{ value }}</gl-link>
<gl-link :href="linkToCommit">{{ value }}</gl-link>
</template>
......@@ -8,7 +8,9 @@ export default (el) => {
return null;
}
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability), {
const { vulnerability: rawVulnerability, projectCommitPath } = el.dataset;
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(rawVulnerability), {
deep: true,
});
......@@ -18,6 +20,7 @@ export default (el) => {
provide: {
reportType: vulnerability.reportType,
newIssueUrl: vulnerability.newIssueUrl,
projectCommitPath,
projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id,
......
......@@ -21,6 +21,7 @@
empty_state_unauthorized_svg_path: image_path('illustrations/user-not-logged-in.svg'),
empty_state_forbidden_svg_path: image_path('illustrations/lock_promotion.svg'),
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,
security_report_help_page_link: help_page_path('user/application_security/index', anchor: 'security-report-validation') } }
......
......@@ -3,7 +3,7 @@
- breadcrumb_title @vulnerability.id
- page_title @vulnerability.title
- page_description @vulnerability.description
- vulnerability_init_details = { vulnerability: vulnerability_details_json(@vulnerability, @pipeline)}
- 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
const TEST_DATA = {
value: '24922148',
};
const TEST_PROJECT_COMMIT_PATH = '/foo/bar';
describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () => {
let wrapper;
const createWrapper = ({ provide } = {}) => {
const createWrapper = () => {
return shallowMount(Commit, {
propsData: TEST_DATA,
provide: {
projectFullPath: '',
...provide,
projectCommitPath: TEST_PROJECT_COMMIT_PATH,
},
});
};
const findLink = () => wrapper.findComponent(GlLink);
beforeEach(() => {
wrapper = createWrapper();
});
afterEach(() => {
wrapper.destroy();
});
it.each(['/foo/bar', 'foo/bar'])(
'given `projectFullPath` is "%s" it links to the absolute path of the commit',
(projectFullPath) => {
const absoluteCommitPath = `/foo/bar/-/commit/${TEST_DATA.value}`;
wrapper = createWrapper({ provide: { projectFullPath } });
expect(findLink().attributes('href')).toBe(absoluteCommitPath);
},
);
it('links to the given commit hash', () => {
expect(findLink().attributes('href')).toBe(`${TEST_PROJECT_COMMIT_PATH}/${TEST_DATA.value}`);
});
it('shows the value as the link-text', () => {
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