Commit 6485ebb5 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '207448_cleanup_legacy_findings_logic' into 'master'

Cleanup legacy findings logic

See merge request gitlab-org/gitlab!35800
parents 8b4932c0 64a8dfa6
......@@ -41,7 +41,7 @@ export default {
required: false,
default: '',
},
hasPipelineData: {
hasVulnerabilities: {
type: Boolean,
required: false,
default: false,
......@@ -89,7 +89,7 @@ export default {
<template>
<div>
<template v-if="hasPipelineData">
<template v-if="hasVulnerabilities">
<security-dashboard-layout>
<template #header>
<gl-banner
......
......@@ -19,7 +19,7 @@ export default {
UserAvatarLink,
},
props: {
hasPipelineData: {
hasVulnerabilities: {
type: Boolean,
required: false,
default: false,
......@@ -85,7 +85,7 @@ export default {
</script>
<template>
<div>
<template v-if="hasPipelineData">
<template v-if="hasVulnerabilities">
<div class="card security-dashboard gl-mt-3">
<div class="card-header border-bottom-0">
<span class="js-security-dashboard-left">
......
......@@ -36,7 +36,7 @@ export default (
const props = {
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
dashboardDocumentation: el.dataset.dashboardDocumentation,
hasPipelineData: Boolean(el.dataset.hasPipelineData),
hasVulnerabilities: Boolean(el.dataset.hasVulnerabilities),
securityDashboardHelpPath: el.dataset.securityDashboardHelpPath,
projectAddEndpoint: el.dataset.projectAddEndpoint,
projectListEndpoint: el.dataset.projectListEndpoint,
......
......@@ -8,10 +8,10 @@ export default () => {
const securityTab = document.getElementById('js-security-report-app');
const props = {
...securityTab.dataset,
hasPipelineData: parseBoolean(securityTab.dataset.hasPipelineData),
hasVulnerabilities: parseBoolean(securityTab.dataset.hasVulnerabilities),
};
if (props.hasPipelineData) {
if (props.hasVulnerabilities) {
Object.assign(props, {
project: {
id: props.projectId,
......
......@@ -10,11 +10,6 @@ module Projects
before_action only: [:index] do
push_frontend_feature_flag(:hide_dismissed_vulnerabilities)
end
def index
@pipeline = @project.latest_pipeline_with_security_reports
&.present(current_user: current_user)
end
end
end
end
......@@ -174,14 +174,16 @@ module EE
::Project.in_namespace(allowed_subgroups).count
end
def project_security_dashboard_config(project, pipeline)
def project_security_dashboard_config(project)
if project.vulnerabilities.none?
{
has_vulnerabilities: 'false',
empty_state_svg_path: image_path('illustrations/security-dashboard_empty.svg'),
security_dashboard_help_path: help_page_path('user/application_security/security_dashboard/index')
}
else
{
has_vulnerabilities: 'true',
project: { id: project.id, name: project.name },
project_full_path: project.full_path,
vulnerabilities_endpoint: project_security_vulnerability_findings_path(project),
......@@ -194,37 +196,10 @@ module EE
user_callouts_path: user_callouts_path,
user_callout_id: UserCalloutsHelper::STANDALONE_VULNERABILITIES_INTRODUCTION_BANNER,
show_introduction_banner: show_standalone_vulnerabilities_introduction_banner?.to_s
}.merge!(
project_vulnerabilities_config(project),
security_dashboard_pipeline_data(project, pipeline)
)
}
end
end
# TODO(@gitlab-org/defend/backend): Remove this method and it's
# references with https://gitlab.com/gitlab-org/gitlab/-/issues/207448.
def security_dashboard_pipeline_data(project, pipeline)
return { has_pipeline_data: 'false' } unless pipeline
{
pipeline_id: pipeline.id,
user_path: pipeline.user && user_url(pipeline.user),
user_avatar_path: pipeline.user&.avatar_url,
user_name: pipeline.user&.name,
commit_id: pipeline.commit.short_id,
commit_path: project_commit_url(project, pipeline.commit),
ref_id: pipeline.ref,
ref_path: project_commits_url(project, pipeline.ref),
pipeline_path: pipeline_url(pipeline),
pipeline_created: pipeline.created_at.to_s(:iso8601),
has_pipeline_data: 'true'
}
end
def project_vulnerabilities_config(project)
{ vulnerabilities_export_endpoint: api_v4_security_projects_vulnerability_exports_path(id: project.id) }
end
def can_create_feedback?(project, feedback_type)
feedback = Vulnerabilities::Feedback.new(project: project, feedback_type: feedback_type)
can?(current_user, :create_vulnerability_feedback, feedback)
......
- breadcrumb_title _("Security Dashboard")
- page_title _("Security Dashboard")
#js-security-report-app{ data: project_security_dashboard_config(@project, @pipeline) }
#js-security-report-app{ data: project_security_dashboard_config(@project) }
......@@ -51,9 +51,9 @@ describe('First class Project Security Dashboard component', () => {
wrapper = null;
});
describe('on render when pipeline has data', () => {
describe('on render when there are vulnerabilities', () => {
beforeEach(() => {
createComponent({ props: { hasPipelineData: true } });
createComponent({ props: { hasVulnerabilities: true } });
});
it('should render the vulnerabilities', () => {
......@@ -89,7 +89,7 @@ describe('First class Project Security Dashboard component', () => {
beforeEach(() => {
mockAxios = new MockAdapter(axios);
mockAxios.onPost(props.userCalloutsPath, { feature_name: props.userCalloutId }).reply(200);
createComponent({ props: { hasPipelineData: true, showIntroductionBanner: true } });
createComponent({ props: { hasVulnerabilities: true, showIntroductionBanner: true } });
});
afterEach(() => {
......@@ -125,7 +125,7 @@ describe('First class Project Security Dashboard component', () => {
describe('when user already dismissed the banner in the past', () => {
beforeEach(() => {
Cookies.set(BANNER_COOKIE_KEY, 'true');
createComponent({ props: { hasPipelineData: true, showIntroductionBanner: true } });
createComponent({ props: { hasVulnerabilities: true, showIntroductionBanner: true } });
});
afterEach(() => {
......@@ -141,7 +141,7 @@ describe('First class Project Security Dashboard component', () => {
beforeEach(() => {
createComponent({
props: {
hasPipelineData: true,
hasVulnerabilities: true,
},
data() {
return { filters };
......@@ -154,11 +154,11 @@ describe('First class Project Security Dashboard component', () => {
});
});
describe('when pipeline has no data', () => {
describe('when there is no vulnerability', () => {
beforeEach(() => {
createComponent({
props: {
hasPipelineData: false,
hasVulnerabilities: false,
},
});
});
......
......@@ -22,7 +22,7 @@ describe('Project Security Dashboard component', () => {
store: createStore(),
stubs: ['security-dashboard-table'],
propsData: {
hasPipelineData: true,
hasVulnerabilities: true,
emptyStateSvgPath: `${TEST_HOST}/img`,
securityDashboardHelpPath: `${TEST_HOST}/help_dashboard`,
commit: {
......@@ -108,7 +108,7 @@ describe('Project Security Dashboard component', () => {
describe('Empty State renders correctly', () => {
beforeEach(() => {
createComponent({ hasPipelineData: false });
createComponent({ hasVulnerabilities: false });
});
it('renders empty state component with correct props', () => {
......
......@@ -92,9 +92,7 @@ RSpec.describe ProjectsHelper do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let(:pipeline) { nil }
subject { helper.project_security_dashboard_config(project, pipeline) }
subject { helper.project_security_dashboard_config(project) }
before do
group.add_owner(user)
......@@ -104,6 +102,7 @@ RSpec.describe ProjectsHelper do
context 'project without vulnerabilities' do
let(:expected_value) do
{
has_vulnerabilities: 'false',
empty_state_svg_path: start_with('/assets/illustrations/security-dashboard_empty'),
security_dashboard_help_path: '/help/user/application_security/security_dashboard/index'
}
......@@ -117,12 +116,14 @@ RSpec.describe ProjectsHelper do
create(:vulnerability, project: project)
end
let(:expected_core_values) do
hash_including(
let(:expected_values) do
{
has_vulnerabilities: 'true',
project: { id: project.id, name: project.name },
project_full_path: project.full_path,
vulnerabilities_endpoint: "/#{project.full_path}/-/security/vulnerability_findings",
vulnerabilities_summary_endpoint: "/#{project.full_path}/-/security/vulnerability_findings/summary",
vulnerabilities_export_endpoint: "/api/v4/security/projects/#{project.id}/vulnerability_exports",
vulnerability_feedback_help_path: '/help/user/application_security/index#interacting-with-the-vulnerabilities',
empty_state_svg_path: start_with('/assets/illustrations/security-dashboard-empty-state'),
dashboard_documentation: '/help/user/application_security/security_dashboard/index',
......@@ -130,51 +131,10 @@ RSpec.describe ProjectsHelper do
user_callouts_path: '/-/user_callouts',
user_callout_id: 'standalone_vulnerabilities_introduction_banner',
show_introduction_banner: 'true'
)
end
it { is_expected.to match(expected_core_values) }
context 'project without pipeline' do
let(:expected_sub_hash) do
hash_including(
has_pipeline_data: 'false'
)
end
it { is_expected.to match(expected_sub_hash) }
}
end
context 'project with pipeline' do
let_it_be(:pipeline) do
create(:ee_ci_pipeline,
:with_sast_report,
user: user,
project: project,
ref: project.default_branch,
sha: project.commit.sha)
end
let(:project_path) { "http://test.host/#{project.full_path}" }
let(:expected_sub_hash) do
hash_including(
pipeline_id: pipeline.id,
user_path: "http://test.host/#{pipeline.user.username}",
user_avatar_path: pipeline.user.avatar_url,
user_name: pipeline.user.name,
commit_id: pipeline.commit.short_id,
commit_path: "#{project_path}/-/commit/#{pipeline.commit.sha}",
ref_id: project.default_branch,
ref_path: "#{project_path}/-/commits/#{project.default_branch}",
pipeline_path: "#{project_path}/-/pipelines/#{pipeline.id}",
pipeline_created: pipeline.created_at.to_s(:iso8601),
has_pipeline_data: 'true',
vulnerabilities_export_endpoint: "/api/v4/security/projects/#{project.id}/vulnerability_exports"
)
end
it { is_expected.to match(expected_sub_hash) }
end
it { is_expected.to match(expected_values) }
end
end
......
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