2016-08-13 08:45:31 -04:00
|
|
|
module Groups
|
|
|
|
class DestroyService < Groups::BaseService
|
|
|
|
def async_execute
|
2017-06-23 20:02:33 -04:00
|
|
|
group.soft_delete_without_removing_associations
|
2016-08-13 08:45:31 -04:00
|
|
|
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
|
|
|
|
Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2017-02-16 02:50:05 -05:00
|
|
|
group.prepare_for_destroy
|
|
|
|
|
2017-06-15 08:06:49 -04:00
|
|
|
group.projects.each do |project|
|
2016-08-13 08:45:31 -04:00
|
|
|
# Execute the destruction of the models immediately to ensure atomic cleanup.
|
|
|
|
# Skip repository removal because we remove directory with namespace
|
|
|
|
# that contain all these repositories
|
2017-08-21 09:28:07 -04:00
|
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: project.legacy_storage?).execute
|
2016-08-13 08:45:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
group.children.each do |group|
|
2017-02-15 20:15:54 -05:00
|
|
|
# This needs to be synchronous since the namespace gets destroyed below
|
|
|
|
DestroyService.new(group, current_user).execute
|
2016-08-13 08:45:31 -04:00
|
|
|
end
|
|
|
|
|
2017-05-14 06:57:08 -04:00
|
|
|
group.chat_team&.remove_mattermost_team(current_user)
|
|
|
|
|
2016-08-13 08:45:31 -04:00
|
|
|
group.really_destroy!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|