Commit 64a8dfa6 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Remove legacy code from ProjectsHelper

This code was used by old security dashboard which can not be accessed
since we removed the feature flag.

Also renamed the `hasPipelineData` property as `hasVulnerabilities` as
we are not depending anymore on pipeline data to load our dashboard.
parent f316f047
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
hasPipelineData: { hasVulnerabilities: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
<template> <template>
<div> <div>
<template v-if="hasPipelineData"> <template v-if="hasVulnerabilities">
<security-dashboard-layout> <security-dashboard-layout>
<template #header> <template #header>
<gl-banner <gl-banner
......
...@@ -19,7 +19,7 @@ export default { ...@@ -19,7 +19,7 @@ export default {
UserAvatarLink, UserAvatarLink,
}, },
props: { props: {
hasPipelineData: { hasVulnerabilities: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -85,7 +85,7 @@ export default { ...@@ -85,7 +85,7 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<template v-if="hasPipelineData"> <template v-if="hasVulnerabilities">
<div class="card security-dashboard gl-mt-3"> <div class="card security-dashboard gl-mt-3">
<div class="card-header border-bottom-0"> <div class="card-header border-bottom-0">
<span class="js-security-dashboard-left"> <span class="js-security-dashboard-left">
......
...@@ -36,7 +36,7 @@ export default ( ...@@ -36,7 +36,7 @@ export default (
const props = { const props = {
emptyStateSvgPath: el.dataset.emptyStateSvgPath, emptyStateSvgPath: el.dataset.emptyStateSvgPath,
dashboardDocumentation: el.dataset.dashboardDocumentation, dashboardDocumentation: el.dataset.dashboardDocumentation,
hasPipelineData: Boolean(el.dataset.hasPipelineData), hasVulnerabilities: Boolean(el.dataset.hasVulnerabilities),
securityDashboardHelpPath: el.dataset.securityDashboardHelpPath, securityDashboardHelpPath: el.dataset.securityDashboardHelpPath,
projectAddEndpoint: el.dataset.projectAddEndpoint, projectAddEndpoint: el.dataset.projectAddEndpoint,
projectListEndpoint: el.dataset.projectListEndpoint, projectListEndpoint: el.dataset.projectListEndpoint,
......
...@@ -8,10 +8,10 @@ export default () => { ...@@ -8,10 +8,10 @@ export default () => {
const securityTab = document.getElementById('js-security-report-app'); const securityTab = document.getElementById('js-security-report-app');
const props = { const props = {
...securityTab.dataset, ...securityTab.dataset,
hasPipelineData: parseBoolean(securityTab.dataset.hasPipelineData), hasVulnerabilities: parseBoolean(securityTab.dataset.hasVulnerabilities),
}; };
if (props.hasPipelineData) { if (props.hasVulnerabilities) {
Object.assign(props, { Object.assign(props, {
project: { project: {
id: props.projectId, id: props.projectId,
......
...@@ -10,11 +10,6 @@ module Projects ...@@ -10,11 +10,6 @@ module Projects
before_action only: [:index] do before_action only: [:index] do
push_frontend_feature_flag(:hide_dismissed_vulnerabilities) push_frontend_feature_flag(:hide_dismissed_vulnerabilities)
end end
def index
@pipeline = @project.latest_pipeline_with_security_reports
&.present(current_user: current_user)
end
end end
end end
end end
...@@ -174,14 +174,16 @@ module EE ...@@ -174,14 +174,16 @@ module EE
::Project.in_namespace(allowed_subgroups).count ::Project.in_namespace(allowed_subgroups).count
end end
def project_security_dashboard_config(project, pipeline) def project_security_dashboard_config(project)
if project.vulnerabilities.none? if project.vulnerabilities.none?
{ {
has_vulnerabilities: 'false',
empty_state_svg_path: image_path('illustrations/security-dashboard_empty.svg'), empty_state_svg_path: image_path('illustrations/security-dashboard_empty.svg'),
security_dashboard_help_path: help_page_path('user/application_security/security_dashboard/index') security_dashboard_help_path: help_page_path('user/application_security/security_dashboard/index')
} }
else else
{ {
has_vulnerabilities: 'true',
project: { id: project.id, name: project.name }, project: { id: project.id, name: project.name },
project_full_path: project.full_path, project_full_path: project.full_path,
vulnerabilities_endpoint: project_security_vulnerability_findings_path(project), vulnerabilities_endpoint: project_security_vulnerability_findings_path(project),
...@@ -194,35 +196,8 @@ module EE ...@@ -194,35 +196,8 @@ module EE
user_callouts_path: user_callouts_path, user_callouts_path: user_callouts_path,
user_callout_id: UserCalloutsHelper::STANDALONE_VULNERABILITIES_INTRODUCTION_BANNER, user_callout_id: UserCalloutsHelper::STANDALONE_VULNERABILITIES_INTRODUCTION_BANNER,
show_introduction_banner: show_standalone_vulnerabilities_introduction_banner?.to_s 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 end
def project_vulnerabilities_config(project)
{ vulnerabilities_export_endpoint: api_v4_security_projects_vulnerability_exports_path(id: project.id) }
end end
def can_create_feedback?(project, feedback_type) def can_create_feedback?(project, feedback_type)
......
- breadcrumb_title _("Security Dashboard") - breadcrumb_title _("Security Dashboard")
- page_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', () => { ...@@ -51,9 +51,9 @@ describe('First class Project Security Dashboard component', () => {
wrapper = null; wrapper = null;
}); });
describe('on render when pipeline has data', () => { describe('on render when there are vulnerabilities', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ props: { hasPipelineData: true } }); createComponent({ props: { hasVulnerabilities: true } });
}); });
it('should render the vulnerabilities', () => { it('should render the vulnerabilities', () => {
...@@ -89,7 +89,7 @@ describe('First class Project Security Dashboard component', () => { ...@@ -89,7 +89,7 @@ describe('First class Project Security Dashboard component', () => {
beforeEach(() => { beforeEach(() => {
mockAxios = new MockAdapter(axios); mockAxios = new MockAdapter(axios);
mockAxios.onPost(props.userCalloutsPath, { feature_name: props.userCalloutId }).reply(200); mockAxios.onPost(props.userCalloutsPath, { feature_name: props.userCalloutId }).reply(200);
createComponent({ props: { hasPipelineData: true, showIntroductionBanner: true } }); createComponent({ props: { hasVulnerabilities: true, showIntroductionBanner: true } });
}); });
afterEach(() => { afterEach(() => {
...@@ -125,7 +125,7 @@ describe('First class Project Security Dashboard component', () => { ...@@ -125,7 +125,7 @@ describe('First class Project Security Dashboard component', () => {
describe('when user already dismissed the banner in the past', () => { describe('when user already dismissed the banner in the past', () => {
beforeEach(() => { beforeEach(() => {
Cookies.set(BANNER_COOKIE_KEY, 'true'); Cookies.set(BANNER_COOKIE_KEY, 'true');
createComponent({ props: { hasPipelineData: true, showIntroductionBanner: true } }); createComponent({ props: { hasVulnerabilities: true, showIntroductionBanner: true } });
}); });
afterEach(() => { afterEach(() => {
...@@ -141,7 +141,7 @@ describe('First class Project Security Dashboard component', () => { ...@@ -141,7 +141,7 @@ describe('First class Project Security Dashboard component', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
props: { props: {
hasPipelineData: true, hasVulnerabilities: true,
}, },
data() { data() {
return { filters }; return { filters };
...@@ -154,11 +154,11 @@ describe('First class Project Security Dashboard component', () => { ...@@ -154,11 +154,11 @@ describe('First class Project Security Dashboard component', () => {
}); });
}); });
describe('when pipeline has no data', () => { describe('when there is no vulnerability', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
props: { props: {
hasPipelineData: false, hasVulnerabilities: false,
}, },
}); });
}); });
......
...@@ -22,7 +22,7 @@ describe('Project Security Dashboard component', () => { ...@@ -22,7 +22,7 @@ describe('Project Security Dashboard component', () => {
store: createStore(), store: createStore(),
stubs: ['security-dashboard-table'], stubs: ['security-dashboard-table'],
propsData: { propsData: {
hasPipelineData: true, hasVulnerabilities: true,
emptyStateSvgPath: `${TEST_HOST}/img`, emptyStateSvgPath: `${TEST_HOST}/img`,
securityDashboardHelpPath: `${TEST_HOST}/help_dashboard`, securityDashboardHelpPath: `${TEST_HOST}/help_dashboard`,
commit: { commit: {
...@@ -108,7 +108,7 @@ describe('Project Security Dashboard component', () => { ...@@ -108,7 +108,7 @@ describe('Project Security Dashboard component', () => {
describe('Empty State renders correctly', () => { describe('Empty State renders correctly', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ hasPipelineData: false }); createComponent({ hasVulnerabilities: false });
}); });
it('renders empty state component with correct props', () => { it('renders empty state component with correct props', () => {
......
...@@ -92,9 +92,7 @@ RSpec.describe ProjectsHelper do ...@@ -92,9 +92,7 @@ RSpec.describe ProjectsHelper do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) } let_it_be(:project) { create(:project, :repository, group: group) }
let(:pipeline) { nil } subject { helper.project_security_dashboard_config(project) }
subject { helper.project_security_dashboard_config(project, pipeline) }
before do before do
group.add_owner(user) group.add_owner(user)
...@@ -104,6 +102,7 @@ RSpec.describe ProjectsHelper do ...@@ -104,6 +102,7 @@ RSpec.describe ProjectsHelper do
context 'project without vulnerabilities' do context 'project without vulnerabilities' do
let(:expected_value) do let(:expected_value) do
{ {
has_vulnerabilities: 'false',
empty_state_svg_path: start_with('/assets/illustrations/security-dashboard_empty'), empty_state_svg_path: start_with('/assets/illustrations/security-dashboard_empty'),
security_dashboard_help_path: '/help/user/application_security/security_dashboard/index' security_dashboard_help_path: '/help/user/application_security/security_dashboard/index'
} }
...@@ -117,12 +116,14 @@ RSpec.describe ProjectsHelper do ...@@ -117,12 +116,14 @@ RSpec.describe ProjectsHelper do
create(:vulnerability, project: project) create(:vulnerability, project: project)
end end
let(:expected_core_values) do let(:expected_values) do
hash_including( {
has_vulnerabilities: 'true',
project: { id: project.id, name: project.name }, project: { id: project.id, name: project.name },
project_full_path: project.full_path, project_full_path: project.full_path,
vulnerabilities_endpoint: "/#{project.full_path}/-/security/vulnerability_findings", vulnerabilities_endpoint: "/#{project.full_path}/-/security/vulnerability_findings",
vulnerabilities_summary_endpoint: "/#{project.full_path}/-/security/vulnerability_findings/summary", 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', 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'), empty_state_svg_path: start_with('/assets/illustrations/security-dashboard-empty-state'),
dashboard_documentation: '/help/user/application_security/security_dashboard/index', dashboard_documentation: '/help/user/application_security/security_dashboard/index',
...@@ -130,51 +131,10 @@ RSpec.describe ProjectsHelper do ...@@ -130,51 +131,10 @@ RSpec.describe ProjectsHelper do
user_callouts_path: '/-/user_callouts', user_callouts_path: '/-/user_callouts',
user_callout_id: 'standalone_vulnerabilities_introduction_banner', user_callout_id: 'standalone_vulnerabilities_introduction_banner',
show_introduction_banner: 'true' 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 end
it { is_expected.to match(expected_sub_hash) } it { is_expected.to match(expected_values) }
end
end end
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