Commit 5f9dcb15 authored by David Fernandez's avatar David Fernandez

Merge branch '321884-update-path-redirect' into 'master'

Update policies#new view to pass up updated data

See merge request gitlab-org/gitlab!68317
parents 102224ce a2344dd1
......@@ -15,20 +15,24 @@ module Projects::Security::PoliciesHelper
}
end
def orchestration_policy_data(project, policy_type, policy, environment = nil)
return unless project && policy
def orchestration_policy_data(project, policy_type = nil, policy = nil, environment = nil)
return unless project
disable_scan_execution_update = !can_update_security_orchestration_policy_project?(project)
{
assigned_policy_project: assigned_policy_project(project).to_json,
disable_scan_execution_update: disable_scan_execution_update.to_s,
network_policies_endpoint: project_security_network_policies_path(project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(project),
environment_id: environment&.id,
policy: policy&.to_json,
policy_type: policy_type,
project_path: project.full_path,
project_id: project.id,
policy: policy.to_json,
policy_type: policy_type,
threat_monitoring_path: project_threat_monitoring_path(project)
threat_monitoring_path: project_security_policies_path(project)
}
end
end
- add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policies_path(@project)
- breadcrumb_title s_("SecurityOrchestration|New policy")
- page_title s_("SecurityOrchestration|Policy editor")
- policy_details = policy_details(@project)
- data = orchestration_policy_data(@project)
#js-policy-builder-app{ data: policy_details }
#js-policy-builder-app{ data: data }
......@@ -3,11 +3,11 @@
require 'spec_helper'
RSpec.describe Projects::Security::PoliciesHelper do
describe '#assigned_policy_project' do
let(:project) { create(:project) }
let_it_be_with_reload(:project) { create(:project, :repository, :public) }
describe '#assigned_policy_project' do
context 'when a project does have a security policy project' do
let(:policy_management_project) { create(:project) }
let_it_be(:policy_management_project) { create(:project) }
subject { helper.assigned_policy_project(project) }
......@@ -33,4 +33,56 @@ RSpec.describe Projects::Security::PoliciesHelper do
}
end
end
describe '#orchestration_policy_data' do
let(:owner) { project.owner }
let(:base_data) do
{
assigned_policy_project: "null",
disable_scan_execution_update: "false",
network_policies_endpoint: kind_of(String),
configure_agent_help_path: kind_of(String),
create_agent_help_path: kind_of(String),
environments_endpoint: kind_of(String),
project_path: project.full_path,
project_id: project.id,
threat_monitoring_path: kind_of(String),
environment_id: environment&.id,
policy: policy&.to_json,
policy_type: policy_type
}
end
before do
allow(helper).to receive(:current_user) { owner }
allow(helper).to receive(:can?).with(owner, :update_security_orchestration_policy_project, project) { true }
end
subject { helper.orchestration_policy_data(project, policy_type, policy, environment) }
context 'when a new policy is being created' do
let(:environment) { nil }
let(:policy) { nil }
let(:policy_type) { nil }
it { is_expected.to match(base_data) }
end
context 'when an existing policy is being edited' do
let_it_be(:environment) { create(:environment, project: project) }
let(:policy_type) { 'container_policy' }
let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
)
end
it { is_expected.to match(base_data) }
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