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

destroy_service.rb « parent_links « work_items « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97145d0b3601b13971508c12f45846f8f1a24dc2 (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
35
36
37
38
# frozen_string_literal: true

module WorkItems
  module ParentLinks
    class DestroyService < IssuableLinks::DestroyService
      attr_reader :link, :current_user, :parent, :child

      def initialize(link, user)
        @link = link
        @current_user = user
        @parent = link.work_item_parent
        @child = link.work_item
      end

      private

      def create_notes
        unrelate_note = SystemNoteService.unrelate_work_item(parent, child, current_user)

        ResourceLinkEvent.create(
          user: @current_user,
          work_item: @link.work_item_parent,
          child_work_item: @link.work_item,
          action: ResourceLinkEvent.actions[:remove],
          system_note_metadata_id: unrelate_note&.system_note_metadata&.id
        )
      end

      def not_found_message
        _('No Work Item Link found')
      end

      def permission_to_remove_relation?
        can?(current_user, :admin_parent_link, child) && can?(current_user, :admin_parent_link, parent)
      end
    end
  end
end