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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/work_items/parent_links/base_service.rb')
-rw-r--r--app/services/work_items/parent_links/base_service.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/services/work_items/parent_links/base_service.rb b/app/services/work_items/parent_links/base_service.rb
new file mode 100644
index 00000000000..6f22e09a3fc
--- /dev/null
+++ b/app/services/work_items/parent_links/base_service.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module WorkItems
+ module ParentLinks
+ class BaseService < IssuableLinks::CreateService
+ extend ::Gitlab::Utils::Override
+
+ private
+
+ def set_parent(issuable, work_item)
+ link = WorkItems::ParentLink.for_work_item(work_item)
+ link.work_item_parent = issuable
+ link
+ end
+
+ def create_notes(work_item)
+ SystemNoteService.relate_work_item(issuable, work_item, current_user)
+ end
+
+ def linkable_issuables(work_items)
+ @linkable_issuables ||= if can_admin_link?(issuable)
+ work_items.select { |work_item| linkable?(work_item) }
+ else
+ []
+ end
+ end
+
+ def linkable?(work_item)
+ can_admin_link?(work_item) && previous_related_issuables.exclude?(work_item)
+ end
+
+ def can_admin_link?(work_item)
+ can?(current_user, :admin_parent_link, work_item)
+ end
+
+ override :previous_related_issuables
+ def previous_related_issuables
+ @previous_related_issuables ||= issuable.work_item_children.to_a
+ end
+
+ override :target_issuable_type
+ def target_issuable_type
+ 'work item'
+ end
+
+ override :issuables_not_found_message
+ def issuables_not_found_message
+ format(_('No matching %{issuable} found. Make sure that you are adding a valid %{issuable} ID.'),
+ issuable: target_issuable_type)
+ end
+ end
+ end
+end