summaryrefslogtreecommitdiff
path: root/app/finders/alert_management
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /app/finders/alert_management
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
downloadgitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/finders/alert_management')
-rw-r--r--app/finders/alert_management/http_integrations_finder.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/finders/alert_management/http_integrations_finder.rb b/app/finders/alert_management/http_integrations_finder.rb
new file mode 100644
index 00000000000..9f511be0ace
--- /dev/null
+++ b/app/finders/alert_management/http_integrations_finder.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+module AlertManagement
+ class HttpIntegrationsFinder
+ def initialize(project, params)
+ @project = project
+ @params = params
+ end
+
+ def execute
+ @collection = project.alert_management_http_integrations
+
+ filter_by_availability
+ filter_by_endpoint_identifier
+ filter_by_active
+
+ collection
+ end
+
+ private
+
+ attr_reader :project, :params, :collection
+
+ def filter_by_availability
+ return if multiple_alert_http_integrations?
+
+ first_id = project.alert_management_http_integrations
+ .ordered_by_id
+ .select(:id)
+ .at_most(1)
+
+ @collection = collection.id_in(first_id)
+ end
+
+ def filter_by_endpoint_identifier
+ return unless params[:endpoint_identifier]
+
+ @collection = collection.for_endpoint_identifier(params[:endpoint_identifier])
+ end
+
+ def filter_by_active
+ return unless params[:active]
+
+ @collection = collection.active
+ end
+
+ # Overridden in EE
+ def multiple_alert_http_integrations?
+ false
+ end
+ end
+end
+
+::AlertManagement::HttpIntegrationsFinder.prepend_if_ee('EE::AlertManagement::HttpIntegrationsFinder')