2020-08-20 20:10:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IssuableLinks
|
|
|
|
class DestroyService < BaseService
|
2022-03-04 13:20:01 -05:00
|
|
|
attr_reader :link, :current_user, :source, :target
|
2020-08-20 20:10:44 -04:00
|
|
|
|
|
|
|
def initialize(link, user)
|
|
|
|
@link = link
|
|
|
|
@current_user = user
|
2022-03-04 13:20:01 -05:00
|
|
|
@source = link.source
|
|
|
|
@target = link.target
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return error(not_found_message, 404) unless permission_to_remove_relation?
|
|
|
|
|
|
|
|
remove_relation
|
2021-04-06 14:09:02 -04:00
|
|
|
after_destroy
|
2020-08-20 20:10:44 -04:00
|
|
|
|
|
|
|
success(message: 'Relation was removed')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-03-04 13:20:01 -05:00
|
|
|
def create_notes
|
|
|
|
SystemNoteService.unrelate_issuable(source, target, current_user)
|
|
|
|
SystemNoteService.unrelate_issuable(target, source, current_user)
|
|
|
|
end
|
|
|
|
|
2021-04-06 14:09:02 -04:00
|
|
|
def after_destroy
|
|
|
|
create_notes
|
|
|
|
track_event
|
|
|
|
end
|
|
|
|
|
2020-08-20 20:10:44 -04:00
|
|
|
def remove_relation
|
|
|
|
link.destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_found_message
|
|
|
|
'No Issue Link found'
|
|
|
|
end
|
2022-03-22 08:07:28 -04:00
|
|
|
|
|
|
|
def track_event
|
|
|
|
# no op
|
|
|
|
end
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
end
|