Commit 5a6200ca authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '301005-add-submit-vuln-button' into 'master'

Add button to access new vulnerability form

See merge request gitlab-org/gitlab!81934
parents 06f4c797 f7d186af
---
name: new_vulnerability_form
introduced_by_url:
rollout_issue_url:
milestone: '14.9'
type: development
group: group::threat insights
default_enabled: false
<script> <script>
import { GlSprintf, GlLink } from '@gitlab/ui'; import { GlSprintf, GlLink, GlButton } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import CsvExportButton from '../csv_export_button.vue'; import CsvExportButton from '../csv_export_button.vue';
export default { export default {
components: { GlSprintf, GlLink, CsvExportButton }, components: {
inject: ['dashboardDocumentation'], GlSprintf,
GlLink,
GlButton,
CsvExportButton,
},
mixins: [glFeatureFlagsMixin()],
inject: {
dashboardDocumentation: {
default: '',
},
newVulnerabilityPath: {
default: '',
},
},
computed: {
shouldShowNewVulnerabilityButton() {
return this.glFeatures.newVulnerabilityForm && Boolean(this.newVulnerabilityPath);
},
},
i18n: { i18n: {
title: s__('SecurityReports|Vulnerability Report'), title: s__('SecurityReports|Vulnerability Report'),
submitVulnerability: s__('SecurityReports|Submit vulnerability'),
description: s__( description: s__(
"SecurityReports|The Vulnerability Report shows the results of the latest successful pipeline on your project's default branch, as well as vulnerabilities from your latest container scan. %{linkStart}Learn more.%{linkEnd}", "SecurityReports|The Vulnerability Report shows the results of the latest successful pipeline on your project's default branch, as well as vulnerabilities from your latest container scan. %{linkStart}Learn more.%{linkEnd}",
), ),
...@@ -19,7 +39,16 @@ export default { ...@@ -19,7 +39,16 @@ export default {
<header> <header>
<h2 class="gl-display-flex"> <h2 class="gl-display-flex">
{{ $options.i18n.title }} {{ $options.i18n.title }}
<csv-export-button class="gl-ml-auto" /> <gl-button
v-if="shouldShowNewVulnerabilityButton"
:href="newVulnerabilityPath"
class="gl-ml-auto"
icon="plus"
>
{{ $options.i18n.submitVulnerability }}
</gl-button>
<csv-export-button :class="shouldShowNewVulnerabilityButton ? 'gl-ml-4' : 'gl-ml-auto'" />
/>
</h2> </h2>
<gl-sprintf :message="$options.i18n.description"> <gl-sprintf :message="$options.i18n.description">
......
...@@ -58,6 +58,7 @@ export default (el, dashboardType) => { ...@@ -58,6 +58,7 @@ export default (el, dashboardType) => {
canAdminVulnerability, canAdminVulnerability,
falsePositiveDocUrl, falsePositiveDocUrl,
canViewFalsePositive, canViewFalsePositive,
newVulnerabilityPath,
} = el.dataset; } = el.dataset;
if (isUnavailable) { if (isUnavailable) {
...@@ -103,6 +104,7 @@ export default (el, dashboardType) => { ...@@ -103,6 +104,7 @@ export default (el, dashboardType) => {
), ),
falsePositiveDocUrl, falsePositiveDocUrl,
canViewFalsePositive: parseBoolean(canViewFalsePositive), canViewFalsePositive: parseBoolean(canViewFalsePositive),
newVulnerabilityPath,
}; };
if (dashboardType === DASHBOARD_TYPES.PROJECT) { if (dashboardType === DASHBOARD_TYPES.PROJECT) {
......
...@@ -10,6 +10,7 @@ module Projects ...@@ -10,6 +10,7 @@ module Projects
push_frontend_feature_flag(:vulnerability_management_survey, type: :ops, default_enabled: :yaml) push_frontend_feature_flag(:vulnerability_management_survey, type: :ops, default_enabled: :yaml)
push_frontend_feature_flag(:secure_vulnerability_training, @project, default_enabled: :yaml) push_frontend_feature_flag(:secure_vulnerability_training, @project, default_enabled: :yaml)
push_frontend_feature_flag(:vulnerability_report_pagination, current_user, default_enabled: :yaml) push_frontend_feature_flag(:vulnerability_report_pagination, current_user, default_enabled: :yaml)
push_frontend_feature_flag(:new_vulnerability_form, @project, default_enabled: :yaml)
end end
feature_category :vulnerability_management feature_category :vulnerability_management
......
...@@ -207,7 +207,8 @@ module EE ...@@ -207,7 +207,8 @@ module EE
can_admin_vulnerability: can?(current_user, :admin_vulnerability, project).to_s, can_admin_vulnerability: can?(current_user, :admin_vulnerability, project).to_s,
false_positive_doc_url: help_page_path('user/application_security/vulnerabilities/index'), false_positive_doc_url: help_page_path('user/application_security/vulnerabilities/index'),
can_view_false_positive: can_view_false_positive?, can_view_false_positive: can_view_false_positive?,
security_configuration_path: project_security_configuration_path(@project) security_configuration_path: project_security_configuration_path(@project),
new_vulnerability_path: new_project_security_vulnerability_path(@project)
}.merge!(security_dashboard_pipeline_data(project)) }.merge!(security_dashboard_pipeline_data(project))
end end
end end
......
...@@ -6,10 +6,10 @@ import CsvExportButton from 'ee/security_dashboard/components/shared/csv_export_ ...@@ -6,10 +6,10 @@ import CsvExportButton from 'ee/security_dashboard/components/shared/csv_export_
describe('Vulnerability report header component', () => { describe('Vulnerability report header component', () => {
let wrapper; let wrapper;
const createWrapper = ({ dashboardDocumentation } = {}) => { const createWrapper = ({ provide } = {}) => {
wrapper = mountExtended(VulnerabilityReportHeader, { wrapper = mountExtended(VulnerabilityReportHeader, {
provide: { dashboardDocumentation }, provide,
stubs: { CsvExportButton: true }, stubs: { CsvExportButton: true, GlButton: true },
}); });
}; };
...@@ -17,6 +17,39 @@ describe('Vulnerability report header component', () => { ...@@ -17,6 +17,39 @@ describe('Vulnerability report header component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('shows the submit vulnerability button when new vulnerability path is defined', () => {
createWrapper({
provide: {
newVulnerabilityPath: '/vulnerabilities/new',
glFeatures: { newVulnerabilityForm: true },
},
});
expect(wrapper.findByText('Submit vulnerability').attributes('href')).toBe(
'/vulnerabilities/new',
);
});
it('does not show the submit vulnerability button when new vulnerability path is not defined', () => {
createWrapper({
provide: {
glFeatures: { newVulnerabilityForm: true },
},
});
expect(wrapper.findByText('Submit vulnerability').exists()).toBe(false);
});
it('does not show the submit vulnerability button when the feature flag is not enabled', () => {
createWrapper({
provide: {
newVulnerabilityPath: '/vulnerabilities/new',
},
});
expect(wrapper.findByText('Submit vulnerability').exists()).toBe(false);
});
it('shows the CSV export button', () => { it('shows the CSV export button', () => {
createWrapper(); createWrapper();
...@@ -25,7 +58,7 @@ describe('Vulnerability report header component', () => { ...@@ -25,7 +58,7 @@ describe('Vulnerability report header component', () => {
it('shows the correct link for the documentation', () => { it('shows the correct link for the documentation', () => {
const dashboardDocumentation = 'http://some/link'; const dashboardDocumentation = 'http://some/link';
createWrapper({ dashboardDocumentation }); createWrapper({ provide: { dashboardDocumentation } });
expect(wrapper.findComponent(GlLink).attributes('href')).toBe(dashboardDocumentation); expect(wrapper.findComponent(GlLink).attributes('href')).toBe(dashboardDocumentation);
}); });
......
...@@ -229,7 +229,8 @@ RSpec.describe ProjectsHelper do ...@@ -229,7 +229,8 @@ RSpec.describe ProjectsHelper do
scanners: '[{"id":123,"vendor":"Security Vendor","report_type":"SAST"}]', scanners: '[{"id":123,"vendor":"Security Vendor","report_type":"SAST"}]',
can_admin_vulnerability: 'true', can_admin_vulnerability: 'true',
can_view_false_positive: 'false', can_view_false_positive: 'false',
security_configuration_path: kind_of(String) security_configuration_path: kind_of(String),
new_vulnerability_path: end_with('/security/vulnerabilities/new')
} }
end end
......
...@@ -33025,6 +33025,9 @@ msgstr "" ...@@ -33025,6 +33025,9 @@ msgstr ""
msgid "SecurityReports|Status" msgid "SecurityReports|Status"
msgstr "" msgstr ""
msgid "SecurityReports|Submit vulnerability"
msgstr ""
msgid "SecurityReports|Take survey" msgid "SecurityReports|Take survey"
msgstr "" msgstr ""
......
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