Commit 30e86f1e authored by Alexander Turinske's avatar Alexander Turinske

Remove unused threat monitoring pages

- remove edit page
- remove new page
- update tests
- remove unused helpers
- move helper files to match standards
parent a07a65b5
import initPolicyEditorApp from 'ee/threat_monitoring/policy_editor';
initPolicyEditorApp();
import initPolicyEditorApp from 'ee/threat_monitoring/policy_editor';
initPolicyEditorApp();
# frozen_string_literal: true
module PolicyHelper
def policy_details(project, policy = nil, environment = nil)
return unless project
details = details(project)
return details unless policy && environment
edit_details = {
policy: policy.to_json,
environment_id: environment.id
}
details.merge(edit_details)
end
def threat_monitoring_alert_details_data(project, alert_iid)
{
'alert-id' => alert_iid,
'project-path' => project.full_path,
'project-id' => project.id,
'project-issues-path' => project_issues_path(project),
'page' => 'THREAT_MONITORING'
}
end
private
def details(project)
disable_scan_execution_update = !can_update_security_orchestration_policy_project?(project)
{
assigned_policy_project: assigned_policy_project(project).to_json,
default_environment_id: project.default_environment&.id || -1,
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),
network_documentation_path: help_page_path('user/application_security/policies/index'),
no_environment_svg_path: image_path('illustrations/monitoring/unable_to_connect.svg'),
project_path: project.full_path,
project_id: project.id,
threat_monitoring_path: project_threat_monitoring_path(project)
}
end
end
# frozen_string_literal: true
module Projects::ThreatMonitoringHelper
def threat_monitoring_alert_details_data(project, alert_iid)
{
'alert-id' => alert_iid,
'project-path' => project.full_path,
'project-id' => project.id,
'project-issues-path' => project_issues_path(project),
'page' => 'THREAT_MONITORING'
}
end
end
- add_to_breadcrumbs s_("ThreatMonitoring|Threat Monitoring"), project_threat_monitoring_path(@project)
- breadcrumb_title @policy_name
- page_title s_("NetworkPolicies|Policy editor")
- policy_details = policy_details(@project, @policy, @environment)
#js-policy-builder-app{ data: policy_details }
- add_to_breadcrumbs s_("ThreatMonitoring|Threat Monitoring"), project_threat_monitoring_path(@project)
- breadcrumb_title s_("NetworkPolicies|New policy")
- page_title s_("NetworkPolicies|Policy editor")
- policy_details = policy_details(@project)
#js-policy-builder-app{ data: policy_details }
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe PolicyHelper do
let(:project) { create(:project, :repository, :public) }
let(:environment) { create(:environment, project: project) }
let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
)
end
let(:base_data) do
{
assigned_policy_project: "null",
default_environment_id: -1,
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),
network_documentation_path: kind_of(String),
no_environment_svg_path: kind_of(String),
project_path: project.full_path,
project_id: project.id,
threat_monitoring_path: kind_of(String)
}
end
describe '#policy_details' do
let(:owner) { project.owner }
before do
allow(helper).to receive(:current_user) { owner }
allow(helper).to receive(:can?).with(owner, :update_security_orchestration_policy_project, project) { true }
end
context 'when a new policy is being created' do
subject { helper.policy_details(project) }
it 'returns expected policy data' do
expect(subject).to match(base_data)
end
end
context 'when an existing policy is being edited' do
subject { helper.policy_details(project, policy, environment) }
it 'returns expected policy data' do
expect(subject).to match(
base_data.merge(
default_environment_id: project.default_environment.id,
policy: policy.to_json,
environment_id: environment.id
)
)
end
end
context 'when no environment is passed in' do
subject { helper.policy_details(project, policy) }
it 'returns expected policy data' do
expect(subject).to match(base_data)
end
end
end
describe '#policy_alert_details' do
let(:alert) { build(:alert_management_alert, project: project) }
context 'when a new alert is created' do
subject { helper.threat_monitoring_alert_details_data(project, alert.iid) }
it 'returns expected policy data' do
expect(subject).to match({
'alert-id' => alert.iid,
'project-path' => project.full_path,
'project-id' => project.id,
'project-issues-path' => project_issues_path(project),
'page' => 'THREAT_MONITORING'
})
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ThreatMonitoringHelper do
let(:project) { create(:project, :repository, :public) }
describe '#policy_alert_details' do
let(:alert) { build(:alert_management_alert, project: project) }
context 'when a new alert is created' do
subject { helper.threat_monitoring_alert_details_data(project, alert.iid) }
it 'returns expected policy data' do
expect(subject).to match({
'alert-id' => alert.iid,
'project-path' => project.full_path,
'project-id' => project.id,
'project-issues-path' => project_issues_path(project),
'page' => 'THREAT_MONITORING'
})
end
end
end
end
...@@ -22556,9 +22556,6 @@ msgstr "" ...@@ -22556,9 +22556,6 @@ msgstr ""
msgid "NetworkPolicies|Policy definition" msgid "NetworkPolicies|Policy definition"
msgstr "" msgstr ""
msgid "NetworkPolicies|Policy editor"
msgstr ""
msgid "NetworkPolicies|Rule" msgid "NetworkPolicies|Rule"
msgstr "" msgstr ""
......
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