Commit 32bde0c6 authored by Nick Thomas's avatar Nick Thomas

Merge branch '323240-generate-link-to-threat-management-alert' into 'master'

Update Threat Monitoring Alert to generate valid link

See merge request gitlab-org/gitlab!59724
parents 02aff488 9efe0220
......@@ -112,3 +112,5 @@ module AlertManagement
end
end
end
AlertManagement::AlertPresenter.prepend_if_ee('EE::AlertManagement::AlertPresenter')
# frozen_string_literal: true
module EE
module AlertManagement
module AlertPresenter
extend ActiveSupport::Concern
def details_url
return threat_monitoring_alert_project_threat_monitoring_url(project, alert.iid) if alert.threat_monitoring?
super
end
end
end
end
---
title: Create link to Threat Monitoring Alert for threat management alerts
merge_request: 59724
author:
type: fixed
......@@ -40,7 +40,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :subscriptions, only: [:create, :destroy]
resource :threat_monitoring, only: [:show], controller: :threat_monitoring do
get '/alerts/:id', action: 'alert_details', constraints: { id: /\d+/ }
get '/alerts/:id', action: 'alert_details', constraints: { id: /\d+/ }, as: :threat_monitoring_alert
resources :policies, only: [:new, :edit], controller: :threat_monitoring
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AlertManagement::AlertPresenter do
let_it_be(:project) { create(:project) }
let_it_be(:payload) do
{
'title' => 'Alert title',
'start_time' => '2020-04-27T10:10:22.265949279Z',
'custom' => {
'alert' => {
'fields' => %w[one two]
}
},
'yet' => {
'another' => 73
}
}
end
let_it_be(:alert) { create(:alert_management_alert, :threat_monitoring, project: project, payload: payload) }
subject(:presenter) { described_class.new(alert) }
describe '#issue_description' do
let(:markdown_line_break) { ' ' }
subject { presenter.issue_description }
context 'with threat monitoring alert' do
it do
is_expected.to eq(
<<~MARKDOWN.chomp
**Start time:** #{presenter.start_time}#{markdown_line_break}
**Severity:** #{presenter.severity}#{markdown_line_break}
**GitLab alert:** http://localhost/#{project.full_path}/-/threat_monitoring/alerts/#{alert.iid}
MARKDOWN
)
end
end
end
describe '#details_url' do
context 'when alert has threat_monitoring domain' do
it 'returns the details URL' do
expect(presenter.details_url).to match(%r{#{project.web_url}/-/threat_monitoring/alerts/#{alert.iid}})
end
end
end
end
......@@ -95,6 +95,10 @@ FactoryBot.define do
severity { 'unknown' }
end
trait :threat_monitoring do
domain { :threat_monitoring }
end
trait :prometheus do
monitoring_tool { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus] }
payload 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