diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 21:09:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 21:09:34 +0300 |
commit | a84aefe0bb8fc2ad47ab67cb4ddcfbb7aecfbd5e (patch) | |
tree | dfcd00dc9603a8c652211c6066ceae0c97df1a7f /app/services/incident_management | |
parent | 16cdacff02fbf0069182e090df2eeaa754007957 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/incident_management')
3 files changed, 59 insertions, 18 deletions
diff --git a/app/services/incident_management/link_alerts/base_service.rb b/app/services/incident_management/link_alerts/base_service.rb new file mode 100644 index 00000000000..474a63ab528 --- /dev/null +++ b/app/services/incident_management/link_alerts/base_service.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module IncidentManagement + module LinkAlerts + class BaseService < ::BaseProjectService + private + + attr_reader :incident + + def allowed? + current_user&.can?(:admin_issue, project) + end + + def success + ServiceResponse.success(payload: { incident: incident }) + end + + def error(message) + ServiceResponse.error(message: message) + end + + def error_no_permissions + error(_('You have insufficient permissions to manage alerts for this project')) + end + end + end +end diff --git a/app/services/incident_management/link_alerts/create_service.rb b/app/services/incident_management/link_alerts/create_service.rb index 36f3474fc68..5e5a974efdd 100644 --- a/app/services/incident_management/link_alerts/create_service.rb +++ b/app/services/incident_management/link_alerts/create_service.rb @@ -2,7 +2,7 @@ module IncidentManagement module LinkAlerts - class CreateService < ::BaseProjectService + class CreateService < BaseService # @param incident [Issue] an incident to link alerts # @param current_user [User] # @param alert_references [[String]] a list of alert references. Can be either a short reference or URL @@ -28,7 +28,7 @@ module IncidentManagement private - attr_reader :incident, :current_user, :alert_references + attr_reader :alert_references def extract_alerts_from_references text = alert_references.join(' ') @@ -37,22 +37,6 @@ module IncidentManagement extractor.alerts end - - def allowed? - current_user&.can?(:admin_issue, project) - end - - def success - ServiceResponse.success(payload: { incident: incident }) - end - - def error(message) - ServiceResponse.error(message: message) - end - - def error_no_permissions - error(_('You have insufficient permissions to manage alerts for this project')) - end end end end diff --git a/app/services/incident_management/link_alerts/destroy_service.rb b/app/services/incident_management/link_alerts/destroy_service.rb new file mode 100644 index 00000000000..baeedaf74b6 --- /dev/null +++ b/app/services/incident_management/link_alerts/destroy_service.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module IncidentManagement + module LinkAlerts + class DestroyService < BaseService + # @param incident [Issue] an incident to unlink alert from + # @param current_user [User] + # @param alert [AlertManagement::Alert] an alert to unlink from the incident + def initialize(incident, current_user, alert) + @incident = incident + @current_user = current_user + @alert = alert + + super(project: incident.project, current_user: current_user) + end + + def execute + return error_no_permissions unless allowed? + + incident.alert_management_alerts.delete(alert) + + success + end + + private + + attr_reader :alert + end + end +end |