Commit 11dc34b3 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'ck3g-hide-alert-open-statuses-contant' into 'master'

Hide Alert's open statuses inside a method

See merge request gitlab-org/gitlab!44455
parents 6002ccef b9e9e998
......@@ -21,11 +21,6 @@ module AlertManagement
ignored: 3
}.freeze
OPEN_STATUSES = [
:triggered,
:acknowledged
].freeze
belongs_to :project
belongs_to :issue, optional: true
belongs_to :prometheus_alert, optional: true
......@@ -118,7 +113,7 @@ module AlertManagement
scope :for_fingerprint, -> (project, fingerprint) { where(project: project, fingerprint: fingerprint) }
scope :for_environment, -> (environment) { where(environment: environment) }
scope :search, -> (query) { fuzzy_search(query, [:title, :description, :monitoring_tool, :service]) }
scope :open, -> { with_status(OPEN_STATUSES) }
scope :open, -> { with_status(open_statuses) }
scope :not_resolved, -> { without_status(:resolved) }
scope :with_prometheus_alert, -> { includes(:prometheus_alert) }
......@@ -183,6 +178,14 @@ module AlertManagement
reference.to_i > 0 && reference.to_i <= Gitlab::Database::MAX_INT_VALUE
end
def self.open_statuses
[:triggered, :acknowledged]
end
def self.open_status?(status)
open_statuses.include?(status)
end
def status_event_for(status)
self.class.state_machines[:status].events.transitions_for(self, to: status.to_s.to_sym).first&.event
end
......
......@@ -144,7 +144,7 @@ module AlertManagement
def filter_duplicate
# Only need to check if changing to an open status
return unless params[:status_event] && AlertManagement::Alert::OPEN_STATUSES.include?(status_key)
return unless params[:status_event] && AlertManagement::Alert.open_status?(status_key)
param_errors << unresolved_alert_error if duplicate_alert?
end
......
......@@ -363,6 +363,24 @@ RSpec.describe AlertManagement::Alert do
end
end
describe '.open_status?' do
using RSpec::Parameterized::TableSyntax
where(:status, :is_open_status) do
:triggered | true
:acknowledged | true
:resolved | false
:ignored | false
nil | false
end
with_them do
it 'returns true when the status is open status' do
expect(described_class.open_status?(status)).to eq(is_open_status)
end
end
end
describe '#to_reference' do
it { expect(triggered_alert.to_reference).to eq("^alert##{triggered_alert.iid}") }
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