2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Issuable
|
|
|
|
class DestroyService < IssuableBaseService
|
2023-04-23 21:23:45 +05:30
|
|
|
# TODO: this is to be removed once we get to rename the IssuableBaseService project param to container
|
|
|
|
def initialize(container:, current_user: nil, params: {})
|
2023-05-27 22:25:52 +05:30
|
|
|
super(container: container, current_user: current_user, params: params)
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def execute(issuable)
|
2021-06-08 01:23:25 +05:30
|
|
|
after_destroy(issuable) if issuable.destroy
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def after_destroy(issuable)
|
2021-06-08 01:23:25 +05:30
|
|
|
delete_associated_records(issuable)
|
2021-04-29 21:17:54 +05:30
|
|
|
issuable.update_project_counter_caches
|
|
|
|
issuable.assignees.each(&:invalidate_cache_counts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_for(issuable)
|
|
|
|
issuable.resource_parent.group
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def delete_associated_records(issuable)
|
2021-04-29 21:17:54 +05:30
|
|
|
actor = group_for(issuable)
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
delete_todos(actor, issuable)
|
|
|
|
delete_label_links(actor, issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_todos(actor, issuable)
|
2022-07-16 23:28:13 +05:30
|
|
|
issuable.run_after_commit_or_now do
|
|
|
|
TodosDestroyer::DestroyedIssuableWorker.perform_async(issuable.id, issuable.class.name)
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def delete_label_links(actor, issuable)
|
2022-07-16 23:28:13 +05:30
|
|
|
issuable.run_after_commit_or_now do
|
|
|
|
Issuable::LabelLinksDestroyWorker.perform_async(issuable.id, issuable.class.name)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Issuable::DestroyService.prepend_mod_with('Issuable::DestroyService')
|