debian-mirror-gitlab/app/services/issuable_links/destroy_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
907 B
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
module IssuableLinks
class DestroyService < BaseService
2022-05-07 20:08:51 +05:30
attr_reader :link, :current_user, :source, :target
2020-11-24 15:15:51 +05:30
def initialize(link, user)
@link = link
@current_user = user
2022-05-07 20:08:51 +05:30
@source = link.source
@target = link.target
2020-11-24 15:15:51 +05:30
end
def execute
return error(not_found_message, 404) unless permission_to_remove_relation?
remove_relation
2021-04-29 21:17:54 +05:30
after_destroy
2020-11-24 15:15:51 +05:30
success(message: 'Relation was removed')
end
private
2022-05-07 20:08:51 +05:30
def create_notes
SystemNoteService.unrelate_issuable(source, target, current_user)
SystemNoteService.unrelate_issuable(target, source, current_user)
end
2021-04-29 21:17:54 +05:30
def after_destroy
create_notes
track_event
end
2020-11-24 15:15:51 +05:30
def remove_relation
link.destroy!
end
def not_found_message
'No Issue Link found'
end
2022-06-21 17:19:12 +05:30
def track_event
# no op
end
2020-11-24 15:15:51 +05:30
end
end