Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unlink_alert.rb « issues « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a11af4133cf43f523b4da68640bc50b5c89dced5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Mutations
  module Issues
    class UnlinkAlert < Base
      graphql_name 'IssueUnlinkAlert'

      argument :alert_id, ::Types::GlobalIDType[::AlertManagement::Alert],
        required: true,
        description: 'Global ID of the alert to unlink from the incident.'

      authorize :admin_issue

      def resolve(project_path:, iid:, alert_id:)
        issue = authorized_find!(project_path: project_path, iid: iid)
        alert = find_alert_by_gid(alert_id)

        result = ::IncidentManagement::LinkAlerts::DestroyService.new(issue, current_user, alert).execute

        {
          issue: issue,
          errors: result.errors
        }
      end

      private

      def find_alert_by_gid(alert_id)
        ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(alert_id, expected_type: ::AlertManagement::Alert))
      end
    end
  end
end