debian-mirror-gitlab/app/helpers/projects/alert_management_helper.rb

43 lines
1.6 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Projects::AlertManagementHelper
def alert_management_data(current_user, project)
{
'project-path' => project.full_path,
2020-07-28 23:09:34 +05:30
'enable-alert-management-path' => project_settings_operations_path(project, anchor: 'js-alert-management-settings'),
2021-03-11 19:13:27 +05:30
'alerts-help-url' => help_page_url('operations/incident_management/alerts.md'),
'populating-alerts-help-url' => help_page_url('operations/incident_management/integrations.md', anchor: 'configuration'),
2020-05-24 23:13:21 +05:30
'empty-alert-svg-path' => image_path('illustrations/alert-management-empty-state.svg'),
2020-07-28 23:09:34 +05:30
'user-can-enable-alert-management' => can?(current_user, :admin_operations, project).to_s,
2021-01-03 14:25:43 +05:30
'alert-management-enabled' => alert_management_enabled?(project).to_s,
2021-06-08 01:23:25 +05:30
'has-managed-prometheus' => has_managed_prometheus?(project).to_s,
2021-01-03 14:25:43 +05:30
'text-query': params[:search],
'assignee-username-query': params[:assignee_username]
2020-05-24 23:13:21 +05:30
}
end
def alert_management_detail_data(project, alert_id)
{
'alert-id' => alert_id,
'project-path' => project.full_path,
2020-07-28 23:09:34 +05:30
'project-id' => project.id,
2021-03-11 19:13:27 +05:30
'project-issues-path' => project_issues_path(project),
'page' => 'OPERATIONS'
2020-05-24 23:13:21 +05:30
}
end
2020-07-28 23:09:34 +05:30
private
2021-06-08 01:23:25 +05:30
def has_managed_prometheus?(project)
project.prometheus_service&.prometheus_available? == true
end
2020-07-28 23:09:34 +05:30
def alert_management_enabled?(project)
2021-01-29 00:20:46 +05:30
!!(
2021-02-22 17:27:13 +05:30
project.alert_management_alerts.any? ||
2021-01-29 00:20:46 +05:30
project.prometheus_service_active? ||
AlertManagement::HttpIntegrationsFinder.new(project, active: true).execute.any?
)
2020-07-28 23:09:34 +05:30
end
2020-05-24 23:13:21 +05:30
end