diff options
Diffstat (limited to 'app/services/issue_links')
-rw-r--r-- | app/services/issue_links/create_service.rb | 46 | ||||
-rw-r--r-- | app/services/issue_links/destroy_service.rb | 28 | ||||
-rw-r--r-- | app/services/issue_links/list_service.rb | 18 |
3 files changed, 92 insertions, 0 deletions
diff --git a/app/services/issue_links/create_service.rb b/app/services/issue_links/create_service.rb new file mode 100644 index 00000000000..63762b1af79 --- /dev/null +++ b/app/services/issue_links/create_service.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module IssueLinks + class CreateService < IssuableLinks::CreateService + # rubocop: disable CodeReuse/ActiveRecord + def relate_issuables(referenced_issue) + link = IssueLink.find_or_initialize_by(source: issuable, target: referenced_issue) + + set_link_type(link) + + if link.changed? && link.save + create_notes(referenced_issue) + end + + link + end + # rubocop: enable CodeReuse/ActiveRecord + + def linkable_issuables(issues) + @linkable_issuables ||= begin + issues.select { |issue| can?(current_user, :admin_issue_link, issue) } + end + end + + def create_notes(referenced_issue) + SystemNoteService.relate_issue(issuable, referenced_issue, current_user) + SystemNoteService.relate_issue(referenced_issue, issuable, current_user) + end + + def previous_related_issuables + @related_issues ||= issuable.related_issues(current_user).to_a + end + + private + + def set_link_type(_link) + # EE only + end + + def track_event + track_incident_action(current_user, issuable, :incident_relate) + end + end +end + +IssueLinks::CreateService.prepend_if_ee('EE::IssueLinks::CreateService') diff --git a/app/services/issue_links/destroy_service.rb b/app/services/issue_links/destroy_service.rb new file mode 100644 index 00000000000..25a45fc697b --- /dev/null +++ b/app/services/issue_links/destroy_service.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module IssueLinks + class DestroyService < IssuableLinks::DestroyService + private + + def source + @source ||= link.source + end + + def target + @target ||= link.target + end + + def permission_to_remove_relation? + can?(current_user, :admin_issue_link, source) && can?(current_user, :admin_issue_link, target) + end + + def create_notes + SystemNoteService.unrelate_issue(source, target, current_user) + SystemNoteService.unrelate_issue(target, source, current_user) + end + + def track_event + track_incident_action(current_user, target, :incident_unrelate) + end + end +end diff --git a/app/services/issue_links/list_service.rb b/app/services/issue_links/list_service.rb new file mode 100644 index 00000000000..5ac731d3fbc --- /dev/null +++ b/app/services/issue_links/list_service.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module IssueLinks + class ListService < IssuableLinks::ListService + extend ::Gitlab::Utils::Override + + private + + def child_issuables + issuable.related_issues(current_user, preload: preload_for_collection) + end + + override :serializer + def serializer + LinkedProjectIssueSerializer + end + end +end |