Commit 1c457ae5 authored by Jannik Lehmann's avatar Jannik Lehmann Committed by Andrew Fontaine

Refactor security configuration page data accumulation

This commit refactors the security configuration
data accumulation to be consistent across CE & EE.
parent 3488a9c8
import { initSecurityConfiguration } from '~/security_configuration'; import { initSecurityConfiguration } from '~/security_configuration';
initSecurityConfiguration(document.querySelector('#js-security-configuration-static')); initSecurityConfiguration(document.querySelector('#js-security-configuration'));
...@@ -159,15 +159,6 @@ export const securityFeatures = [ ...@@ -159,15 +159,6 @@ export const securityFeatures = [
helpPath: SAST_HELP_PATH, helpPath: SAST_HELP_PATH,
configurationHelpPath: SAST_CONFIG_HELP_PATH, configurationHelpPath: SAST_CONFIG_HELP_PATH,
type: REPORT_TYPE_SAST, type: REPORT_TYPE_SAST,
// This field is currently hardcoded because SAST is always available.
// It will eventually come from the Backend, the progress is tracked in
// https://gitlab.com/gitlab-org/gitlab/-/issues/331622
available: true,
// This field is currently hardcoded because SAST can always be enabled via MR
// It will eventually come from the Backend, the progress is tracked in
// https://gitlab.com/gitlab-org/gitlab/-/issues/331621
canEnableByMergeRequest: true,
}, },
{ {
name: SAST_IAC_NAME, name: SAST_IAC_NAME,
...@@ -176,15 +167,6 @@ export const securityFeatures = [ ...@@ -176,15 +167,6 @@ export const securityFeatures = [
helpPath: SAST_IAC_HELP_PATH, helpPath: SAST_IAC_HELP_PATH,
configurationHelpPath: SAST_IAC_CONFIG_HELP_PATH, configurationHelpPath: SAST_IAC_CONFIG_HELP_PATH,
type: REPORT_TYPE_SAST_IAC, type: REPORT_TYPE_SAST_IAC,
// This field is currently hardcoded because SAST IaC is always available.
// It will eventually come from the Backend, the progress is tracked in
// https://gitlab.com/gitlab-org/gitlab/-/issues/331622
available: true,
// This field will eventually come from the backend, the progress is
// tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/331621
canEnableByMergeRequest: true,
}, },
{ {
name: DAST_NAME, name: DAST_NAME,
...@@ -206,10 +188,6 @@ export const securityFeatures = [ ...@@ -206,10 +188,6 @@ export const securityFeatures = [
helpPath: DEPENDENCY_SCANNING_HELP_PATH, helpPath: DEPENDENCY_SCANNING_HELP_PATH,
configurationHelpPath: DEPENDENCY_SCANNING_CONFIG_HELP_PATH, configurationHelpPath: DEPENDENCY_SCANNING_CONFIG_HELP_PATH,
type: REPORT_TYPE_DEPENDENCY_SCANNING, type: REPORT_TYPE_DEPENDENCY_SCANNING,
// This field will eventually come from the backend, the progress is
// tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/331621
canEnableByMergeRequest: true,
}, },
{ {
name: CONTAINER_SCANNING_NAME, name: CONTAINER_SCANNING_NAME,
...@@ -217,10 +195,6 @@ export const securityFeatures = [ ...@@ -217,10 +195,6 @@ export const securityFeatures = [
helpPath: CONTAINER_SCANNING_HELP_PATH, helpPath: CONTAINER_SCANNING_HELP_PATH,
configurationHelpPath: CONTAINER_SCANNING_CONFIG_HELP_PATH, configurationHelpPath: CONTAINER_SCANNING_CONFIG_HELP_PATH,
type: REPORT_TYPE_CONTAINER_SCANNING, type: REPORT_TYPE_CONTAINER_SCANNING,
// This field will eventually come from the backend, the progress is
// tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/331621
canEnableByMergeRequest: true,
}, },
{ {
name: CLUSTER_IMAGE_SCANNING_NAME, name: CLUSTER_IMAGE_SCANNING_NAME,
...@@ -235,16 +209,6 @@ export const securityFeatures = [ ...@@ -235,16 +209,6 @@ export const securityFeatures = [
helpPath: SECRET_DETECTION_HELP_PATH, helpPath: SECRET_DETECTION_HELP_PATH,
configurationHelpPath: SECRET_DETECTION_CONFIG_HELP_PATH, configurationHelpPath: SECRET_DETECTION_CONFIG_HELP_PATH,
type: REPORT_TYPE_SECRET_DETECTION, type: REPORT_TYPE_SECRET_DETECTION,
// This field is currently hardcoded because Secret Detection is always
// available. It will eventually come from the Backend, the progress is
// tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/333113
available: true,
// This field is currently hardcoded because SAST can always be enabled via MR
// It will eventually come from the Backend, the progress is tracked in
// https://gitlab.com/gitlab-org/gitlab/-/issues/331621
canEnableByMergeRequest: true,
}, },
{ {
name: API_FUZZING_NAME, name: API_FUZZING_NAME,
......
...@@ -24,9 +24,6 @@ export default { ...@@ -24,9 +24,6 @@ export default {
enabled() { enabled() {
return this.available && this.feature.configured; return this.available && this.feature.configured;
}, },
hasStatus() {
return !this.available || typeof this.feature.configured === 'boolean';
},
shortName() { shortName() {
return this.feature.shortName ?? this.feature.name; return this.feature.shortName ?? this.feature.name;
}, },
...@@ -93,19 +90,17 @@ export default { ...@@ -93,19 +90,17 @@ export default {
data-testid="feature-status" data-testid="feature-status"
:data-qa-selector="`${feature.type}_status`" :data-qa-selector="`${feature.type}_status`"
> >
<template v-if="hasStatus"> <template v-if="enabled">
<template v-if="enabled"> <gl-icon name="check-circle-filled" />
<gl-icon name="check-circle-filled" /> <span class="gl-text-green-700">{{ $options.i18n.enabled }}</span>
<span class="gl-text-green-700">{{ $options.i18n.enabled }}</span> </template>
</template>
<template v-else-if="available"> <template v-else-if="available">
{{ $options.i18n.notEnabled }} {{ $options.i18n.notEnabled }}
</template> </template>
<template v-else> <template v-else>
{{ $options.i18n.availableWith }} {{ $options.i18n.availableWith }}
</template>
</template> </template>
</div> </div>
</div> </div>
......
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { SCANNER_NAMES_MAP } from '~/security_configuration/components/constants'; import { SCANNER_NAMES_MAP } from '~/security_configuration/components/constants';
/**
* This function takes in 3 arrays of objects, securityFeatures, complianceFeatures and features.
* securityFeatures and complianceFeatures are static arrays living in the constants.
* features is dynamic and coming from the backend.
* This function builds a superset of those arrays.
* It looks for matching keys within the dynamic and the static arrays
* and will enrich the objects with the available static data.
* @param [{}] securityFeatures
* @param [{}] complianceFeatures
* @param [{}] features
* @returns {Object} Object with enriched features from constants divided into Security and Compliance Features
*/
export const augmentFeatures = (securityFeatures, complianceFeatures, features = []) => { export const augmentFeatures = (securityFeatures, complianceFeatures, features = []) => {
const featuresByType = features.reduce((acc, feature) => { const featuresByType = features.reduce((acc, feature) => {
acc[feature.type] = convertObjectPropsToCamelCase(feature, { deep: true }); acc[feature.type] = convertObjectPropsToCamelCase(feature, { deep: true });
......
...@@ -10,6 +10,8 @@ module Projects ...@@ -10,6 +10,8 @@ module Projects
def show def show
render_403 unless can?(current_user, :read_security_configuration, project) render_403 unless can?(current_user, :read_security_configuration, project)
@configuration ||= configuration_presenter
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
......
...@@ -81,7 +81,7 @@ module Projects ...@@ -81,7 +81,7 @@ module Projects
configured: scan.configured?, configured: scan.configured?,
configuration_path: scan.configuration_path, configuration_path: scan.configuration_path,
available: scan.available?, available: scan.available?,
can_enable_in_merge_request: scan.can_enable_in_merge_request? can_enable_by_merge_request: scan.can_enable_by_merge_request?
} }
end end
......
...@@ -2,4 +2,6 @@ ...@@ -2,4 +2,6 @@
- page_title _("Security Configuration") - page_title _("Security Configuration")
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
#js-security-configuration-static{ data: { project_full_path: @project.full_path, upgrade_path: security_upgrade_path } } #js-security-configuration{ data: { **@configuration.to_html_data_attribute,
upgrade_path: security_upgrade_path,
project_full_path: @project.full_path } }
import { initSecurityConfiguration } from '~/security_configuration';
const el =
document.querySelector('#js-security-configuration') ||
document.querySelector('#js-security-configuration-static');
initSecurityConfiguration(el);
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
- page_title _("Security Configuration") - page_title _("Security Configuration")
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
- if @configuration.nil? #js-security-configuration{ data: { **@configuration.to_html_data_attribute,
= render_ce 'projects/security/configuration/show' upgrade_path: security_upgrade_path,
- else project_full_path: @project.full_path } }
#js-security-configuration{ data: { **@configuration.to_html_data_attribute,
project_full_path: @project.full_path,
auto_fix_help_path: '/',
toggle_autofix_setting_endpoint: 'configuration/auto_fix',
container_scanning_help_path: help_page_path('user/application_security/container_scanning/index'),
dependency_scanning_help_path: help_page_path('user/application_security/dependency_scanning/index') } }
...@@ -24,7 +24,7 @@ RSpec.describe Projects::Security::ConfigurationController do ...@@ -24,7 +24,7 @@ RSpec.describe Projects::Security::ConfigurationController do
where(:user_role, :security_dashboard_enabled, :status, :selector) do where(:user_role, :security_dashboard_enabled, :status, :selector) do
:guest | false | :forbidden | nil :guest | false | :forbidden | nil
:guest | true | :forbidden | nil :guest | true | :forbidden | nil
:developer | false | :ok | '#js-security-configuration-static' :developer | false | :ok | '#js-security-configuration'
:developer | true | :ok | '#js-security-configuration' :developer | true | :ok | '#js-security-configuration'
end end
......
...@@ -98,8 +98,8 @@ RSpec.describe ::Gitlab::Security::ScanConfiguration do ...@@ -98,8 +98,8 @@ RSpec.describe ::Gitlab::Security::ScanConfiguration do
end end
end end
describe '#can_enable_in_merge_request?' do describe '#can_enable_by_merge_request?' do
subject { scan.can_enable_in_merge_request? } subject { scan.can_enable_by_merge_request? }
context 'with a scanner that can be enabled in merge request' do context 'with a scanner that can be enabled in merge request' do
where(type: %i(sast sast_iac secret_detection dependency_scanning container_scanning)) where(type: %i(sast sast_iac secret_detection dependency_scanning container_scanning))
......
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
%i[sast sast_iac secret_detection].include?(type) %i[sast sast_iac secret_detection].include?(type)
end end
def can_enable_in_merge_request? def can_enable_by_merge_request?
scans_configurable_in_merge_request.include?(type) scans_configurable_in_merge_request.include?(type)
end end
......
...@@ -113,7 +113,6 @@ describe('FeatureCard component', () => { ...@@ -113,7 +113,6 @@ describe('FeatureCard component', () => {
context | available | configured | expectedStatus context | available | configured | expectedStatus
${'a configured feature'} | ${true} | ${true} | ${'Enabled'} ${'a configured feature'} | ${true} | ${true} | ${'Enabled'}
${'an unconfigured feature'} | ${true} | ${false} | ${'Not enabled'} ${'an unconfigured feature'} | ${true} | ${false} | ${'Not enabled'}
${'an available feature with unknown status'} | ${true} | ${undefined} | ${''}
${'an unavailable feature'} | ${false} | ${false} | ${'Available with Ultimate'} ${'an unavailable feature'} | ${false} | ${false} | ${'Available with Ultimate'}
${'an unavailable feature with unknown status'} | ${false} | ${undefined} | ${'Available with Ultimate'} ${'an unavailable feature with unknown status'} | ${false} | ${undefined} | ${'Available with Ultimate'}
`('given $context', ({ available, configured, expectedStatus }) => { `('given $context', ({ available, configured, expectedStatus }) => {
......
...@@ -47,8 +47,8 @@ RSpec.describe ::Gitlab::Security::ScanConfiguration do ...@@ -47,8 +47,8 @@ RSpec.describe ::Gitlab::Security::ScanConfiguration do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
describe '#can_enable_in_merge_request?' do describe '#can_enable_by_merge_request?' do
subject { scan.can_enable_in_merge_request? } subject { scan.can_enable_by_merge_request? }
let(:configured) { true } let(:configured) { true }
......
...@@ -88,7 +88,7 @@ RSpec.describe Projects::Security::ConfigurationPresenter do ...@@ -88,7 +88,7 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
expect(feature['configured']).to eq(true) expect(feature['configured']).to eq(true)
expect(feature['configuration_path']).to be_nil expect(feature['configuration_path']).to be_nil
expect(feature['available']).to eq(true) expect(feature['available']).to eq(true)
expect(feature['can_enable_in_merge_request']).to eq(true) expect(feature['can_enable_by_merge_request']).to eq(true)
end end
context 'when checking features configured status' do context 'when checking features configured status' do
......
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