2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IssuableLinks
|
|
|
|
class DestroyService < BaseService
|
|
|
|
include IncidentManagement::UsageData
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|