summaryrefslogtreecommitdiff
path: root/app/services/issuable_links/destroy_service.rb
blob: 57e1314e0dae0ade8f58c2160abd69a79a4fcaee (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
34
# frozen_string_literal: true

module IssuableLinks
  class DestroyService < BaseService
    include IncidentManagement::UsageData

    attr_reader :link, :current_user

    def initialize(link, user)
      @link = link
      @current_user = user
    end

    def execute
      return error(not_found_message, 404) unless permission_to_remove_relation?

      remove_relation
      create_notes
      track_event

      success(message: 'Relation was removed')
    end

    private

    def remove_relation
      link.destroy!
    end

    def not_found_message
      'No Issue Link found'
    end
  end
end