diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/editor_wrapper.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/editor_wrapper.vue index e9f878b10942fdd92e412dbdf8b1d38ae2a6dea3..f497a7baa0bef40640eb34416632681b76c44322 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/editor_wrapper.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/editor_wrapper.vue @@ -83,6 +83,12 @@ export default { }; }, computed: { + policyUrlParameter() { + const selectedPolicy = Object.values(POLICY_TYPE_COMPONENT_OPTIONS).find( + ({ value }) => value === this.selectedPolicyType, + ); + return selectedPolicy?.urlParameter || ''; + }, isEditing() { return Boolean(this.existingPolicy); }, @@ -221,6 +227,7 @@ export default { :is-creating="isCreating" :is-deleting="isDeleting" :is-editing="isEditing" + :selected-policy-type="policyUrlParameter" @save="handleSave" @error="setError($event)" /> diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/pipeline_execution/editor_component.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/pipeline_execution/editor_component.vue index 07d2486b321b200a1310fb6d523e347a14fe60bb..627d9f872d288e8227e982702ab0a0934880487d 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/pipeline_execution/editor_component.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/pipeline_execution/editor_component.vue @@ -6,7 +6,6 @@ import { setUrlFragment, queryToObject } from '~/lib/utils/url_utility'; import { s__, __ } from '~/locale'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants'; -import { POLICY_TYPE_COMPONENT_OPTIONS } from 'ee/security_orchestration/components/constants'; import { extractPolicyContent } from 'ee/security_orchestration/components/utils'; import { ACTION_SECTION_DISABLE_ERROR, @@ -33,7 +32,6 @@ export default { ACTION: 'actions', EDITOR_MODE_RULE, EDITOR_MODE_YAML, - POLICY_TYPE: POLICY_TYPE_COMPONENT_OPTIONS.pipelineExecution.urlParameter, SECURITY_POLICY_ACTIONS, i18n: { ACTION_SECTION_DISABLE_ERROR, @@ -81,12 +79,16 @@ export default { type: Boolean, required: true, }, + selectedPolicyType: { + type: String, + required: true, + }, }, data() { let yamlEditorValue; if (this.existingPolicy) { - yamlEditorValue = policyToYaml(this.existingPolicy, this.$options.POLICY_TYPE); + yamlEditorValue = policyToYaml(this.existingPolicy, this.selectedPolicyType); } else { yamlEditorValue = getInitialPolicy( DEFAULT_PIPELINE_EXECUTION_POLICY, @@ -146,7 +148,7 @@ export default { }, methods: { areManifestsEqual(manifest) { - const policyManifest = policyToYaml(this.policy, this.$options.POLICY_TYPE); + const policyManifest = policyToYaml(this.policy, this.selectedPolicyType); return policyManifest === manifest && this.hasNewSplitView; }, changeEditorMode(mode) { @@ -164,7 +166,7 @@ export default { */ const policy = extractPolicyContent({ manifest: this.yamlEditorValue, - type: this.$options.POLICY_TYPE, + type: this.selectedPolicyType, withType: true, }); @@ -216,7 +218,7 @@ export default { this.policy = policy; }, updateYamlEditorValue(policy) { - this.yamlEditorValue = policyToYaml(policy, this.$options.POLICY_TYPE); + this.yamlEditorValue = policyToYaml(policy, this.selectedPolicyType); }, }, }; diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/editor_component.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/editor_component.vue index 29a85101bf3c066d7bca32967254bf7d07eebf0b..7ec5b547872eb0863d691f0f6ec2e3c3a6c5b17d 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/editor_component.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/editor_component.vue @@ -11,10 +11,7 @@ import { extractPolicyContent, } from 'ee/security_orchestration/components/utils'; import OverloadWarningModal from 'ee/security_orchestration/components/overload_warning_modal.vue'; -import { - DEFAULT_SKIP_SI_CONFIGURATION, - POLICY_TYPE_COMPONENT_OPTIONS, -} from 'ee/security_orchestration/components/constants'; +import { DEFAULT_SKIP_SI_CONFIGURATION } from 'ee/security_orchestration/components/constants'; import { policyBodyToYaml, policyToYaml, @@ -52,7 +49,6 @@ export default { RULE: 'rules', EDITOR_MODE_RULE, EDITOR_MODE_YAML, - POLICY_TYPE: POLICY_TYPE_COMPONENT_OPTIONS.scanExecution.urlParameter, SECURITY_POLICY_ACTIONS, i18n: { ACTIONS_LABEL, @@ -139,10 +135,14 @@ export default { type: Boolean, required: true, }, + selectedPolicyType: { + type: String, + required: true, + }, }, data() { const yamlEditorValue = this.existingPolicy - ? policyToYaml(this.existingPolicy, this.$options.POLICY_TYPE) + ? policyToYaml(this.existingPolicy, this.selectedPolicyType) : getPolicyYaml({ isGroup: isGroup(this.namespaceType) }); const { policy, parsingError } = createPolicyObject(yamlEditorValue); @@ -216,7 +216,7 @@ export default { }, methods: { areManifestsEqual(manifest) { - const policyManifest = policyToYaml(this.policy, this.$options.POLICY_TYPE); + const policyManifest = policyToYaml(this.policy, this.selectedPolicyType); return policyManifest === manifest && this.hasNewSplitView; }, addAction() { @@ -292,7 +292,7 @@ export default { */ const policy = extractPolicyContent({ manifest: this.yamlEditorValue, - type: this.$options.POLICY_TYPE, + type: this.selectedPolicyType, withType: true, }); @@ -310,7 +310,7 @@ export default { this.specificActionSectionError = ''; }, updateYamlEditorValue(policy) { - this.yamlEditorValue = policyToYaml(policy, this.$options.POLICY_TYPE); + this.yamlEditorValue = policyToYaml(policy, this.selectedPolicyType); }, }, }; diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_result/editor_component.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_result/editor_component.vue index 18c46026133c516df9299160aa2a91bc7a1d0b5c..f860c82d8bfe6ff3a1f8a5b4336a43e20c76f62d 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_result/editor_component.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_result/editor_component.vue @@ -10,7 +10,6 @@ import { isProject, } from 'ee/security_orchestration/components/utils'; import getSppLinkedProjectsGroups from 'ee/security_orchestration/graphql/queries/get_spp_linked_projects_groups.graphql'; -import { POLICY_TYPE_COMPONENT_OPTIONS } from 'ee/security_orchestration/components/constants'; import { policyBodyToYaml, policyToYaml, @@ -62,7 +61,6 @@ export default { SECURITY_POLICY_ACTIONS, EDITOR_MODE_YAML, EDITOR_MODE_RULE, - POLICY_TYPE: POLICY_TYPE_COMPONENT_OPTIONS.approval.urlParameter, i18n: { ACTION_SECTION_DISABLE_ERROR, ADD_ACTION_LABEL, @@ -173,6 +171,10 @@ export default { type: Boolean, required: true, }, + selectedPolicyType: { + type: String, + required: true, + }, }, data() { const newPolicyYaml = getPolicyYaml({ @@ -180,7 +182,7 @@ export default { }); const yamlEditorValue = this.existingPolicy - ? policyToYaml(this.existingPolicy, this.$options.POLICY_TYPE) + ? policyToYaml(this.existingPolicy, this.selectedPolicyType) : newPolicyYaml; const { policy, parsingError } = createPolicyObject(yamlEditorValue); @@ -335,7 +337,7 @@ export default { }, methods: { areManifestsEqual(manifest) { - const policyManifest = policyToYaml(this.policy, this.$options.POLICY_TYPE); + const policyManifest = policyToYaml(this.policy, this.selectedPolicyType); return policyManifest === manifest && this.hasNewSplitView; }, ruleHasBranchesProperty(rule) { @@ -448,7 +450,7 @@ export default { */ const policy = extractPolicyContent({ manifest: this.yamlEditorValue, - type: this.$options.POLICY_TYPE, + type: this.selectedPolicyType, withType: true, }); @@ -478,7 +480,7 @@ export default { this.policy = policy; }, updateYamlEditorValue(policy) { - this.yamlEditorValue = policyToYaml(policy, this.$options.POLICY_TYPE); + this.yamlEditorValue = policyToYaml(policy, this.selectedPolicyType); }, async changeEditorMode(mode) { this.mode = mode; diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue index 237765ec63335d1c057f8fa0d2952a19d2205f8a..6f1c7d2f2dd218ac27c57be32f4146772811b7c5 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue @@ -2,7 +2,6 @@ import { GlButton, GlTooltipDirective, GlAlert, GlSprintf } from '@gitlab/ui'; import { s__, sprintf, n__ } from '~/locale'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; -import { POLICY_TYPE_COMPONENT_OPTIONS } from 'ee/security_orchestration/components/constants'; import { extractPolicyContent } from 'ee/security_orchestration/components/utils'; import { policyBodyToYaml, @@ -30,7 +29,6 @@ export default { SECURITY_POLICY_ACTIONS, EDITOR_MODE_RULE, EDITOR_MODE_YAML, - POLICY_TYPE: POLICY_TYPE_COMPONENT_OPTIONS.vulnerabilityManagement.urlParameter, i18n: { ACTION_SECTION_DISABLE_ERROR, RULES_SECTION_DISABLE_ERROR, @@ -78,12 +76,16 @@ export default { type: Boolean, required: true, }, + selectedPolicyType: { + type: String, + required: true, + }, }, data() { let yamlEditorValue; if (this.existingPolicy) { - yamlEditorValue = policyToYaml(this.existingPolicy, this.$options.POLICY_TYPE); + yamlEditorValue = policyToYaml(this.existingPolicy, this.selectedPolicyType); } else { yamlEditorValue = DEFAULT_VULNERABILITY_MANAGEMENT_POLICY; } @@ -114,7 +116,7 @@ export default { }, methods: { areManifestsEqual(manifest) { - const policyManifest = policyToYaml(this.policy, this.$options.POLICY_TYPE); + const policyManifest = policyToYaml(this.policy, this.selectedPolicyType); return policyManifest === manifest && this.hasNewSplitView; }, changeEditorMode(mode) { @@ -128,7 +130,7 @@ export default { */ const policy = extractPolicyContent({ manifest: this.yamlEditorValue, - type: this.$options.POLICY_TYPE, + type: this.selectedPolicyType, withType: true, }); @@ -152,7 +154,7 @@ export default { this.policy = policy; }, updateYamlEditorValue(policy) { - this.yamlEditorValue = policyToYaml(policy, this.$options.POLICY_TYPE); + this.yamlEditorValue = policyToYaml(policy, this.selectedPolicyType); }, addRule() { this.policy.rules.push(buildDefaultNoLongerDetectedRule()); diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/editor_wrapper_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/editor_wrapper_spec.js index f7a2b9cf6cf1308118eb8e33ddf52078e4706c8c..a9a25aef0ecde9c8033d9dfbb8b7085166691710 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/editor_wrapper_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/editor_wrapper_spec.js @@ -126,18 +126,19 @@ describe('EditorWrapper component', () => { }); it.each` - policyTypeId | findComponent - ${POLICY_TYPE_COMPONENT_OPTIONS.pipelineExecution.value} | ${findPipelineExecutionPolicyEditor} - ${POLICY_TYPE_COMPONENT_OPTIONS.scanExecution.value} | ${findScanExecutionPolicyEditor} - ${POLICY_TYPE_COMPONENT_OPTIONS.approval.value} | ${findScanResultPolicyEditor} - ${POLICY_TYPE_COMPONENT_OPTIONS.vulnerabilityManagement.value} | ${findVulnerabilityManagementPolicyEditor} + policyTypeId | findComponent | selectedPolicyType + ${POLICY_TYPE_COMPONENT_OPTIONS.pipelineExecution.value} | ${findPipelineExecutionPolicyEditor} | ${POLICY_TYPE_COMPONENT_OPTIONS.pipelineExecution.urlParameter} + ${POLICY_TYPE_COMPONENT_OPTIONS.scanExecution.value} | ${findScanExecutionPolicyEditor} | ${POLICY_TYPE_COMPONENT_OPTIONS.scanExecution.urlParameter} + ${POLICY_TYPE_COMPONENT_OPTIONS.approval.value} | ${findScanResultPolicyEditor} | ${POLICY_TYPE_COMPONENT_OPTIONS.approval.urlParameter} + ${POLICY_TYPE_COMPONENT_OPTIONS.vulnerabilityManagement.value} | ${findVulnerabilityManagementPolicyEditor} | ${POLICY_TYPE_COMPONENT_OPTIONS.vulnerabilityManagement.urlParameter} `( 'renders the policy editor of type $policyType when selected', - ({ findComponent, policyTypeId }) => { + ({ findComponent, policyTypeId, selectedPolicyType }) => { factory({ propsData: { selectedPolicyType: policyTypeId } }); const component = findComponent(); expect(component.exists()).toBe(true); expect(component.props('isEditing')).toBe(false); + expect(component.props('selectedPolicyType')).toBe(selectedPolicyType); }, ); }); diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/pipeline_execution/editor_component_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/pipeline_execution/editor_component_spec.js index e7d75915feedb5d74e82785a1bbe43d77e70766c..be000ce7e80e517978c2d3c10bb71ec9f65209ac 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/pipeline_execution/editor_component_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/pipeline_execution/editor_component_spec.js @@ -59,6 +59,7 @@ describe('EditorComponent', () => { wrapper = shallowMountExtended(EditorComponent, { propsData: { assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, + selectedPolicyType: POLICY_TYPE_COMPONENT_OPTIONS.pipelineExecution.urlParameter, isCreating: false, isDeleting: false, isEditing: false, diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/editor_component_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/editor_component_spec.js index ea2a66671914237290197a3d0ab90159f7fcc02e..cbc3d2aab370c865f60b1042d3b9a65afa102618 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/editor_component_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/editor_component_spec.js @@ -86,6 +86,7 @@ describe('EditorComponent', () => { apolloProvider: createMockApolloProvider(handler), propsData: { assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, + selectedPolicyType: POLICY_TYPE_COMPONENT_OPTIONS.scanExecution.urlParameter, errorSources: [], isCreating: false, isDeleting: false, diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_result/editor_component_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_result/editor_component_spec.js index a1d3efb729f120180d5a96458f58b49997b5a806..9fdabe4153f1a31ad06b9a5ec0608489a29b2c7a 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_result/editor_component_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_result/editor_component_spec.js @@ -108,6 +108,7 @@ describe('EditorComponent', () => { propsData: { assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, errorSources: [], + selectedPolicyType: POLICY_TYPE_COMPONENT_OPTIONS.approval.urlParameter, isCreating: false, isDeleting: false, isEditing: false, diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/vulnerability_management/editor_component_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/vulnerability_management/editor_component_spec.js index dc711a8b5e51625c6972c3abd3e56e976d33265a..31cb2df07078f522a85294f7cc3df3d11a23c960 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/vulnerability_management/editor_component_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/vulnerability_management/editor_component_spec.js @@ -39,6 +39,7 @@ describe('EditorComponent', () => { }, propsData: { assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, + selectedPolicyType: POLICY_TYPE_COMPONENT_OPTIONS.vulnerabilityManagement.urlParameter, isCreating: false, isDeleting: false, isEditing: false,