2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Groups
|
|
|
|
class DestroyService < Groups::BaseService
|
2018-11-20 20:47:30 +05:30
|
|
|
DestroyError = Class.new(StandardError)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def async_execute
|
|
|
|
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::AppLogger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def execute
|
|
|
|
group.prepare_for_destroy
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
group.projects.includes(:project_feature).each do |project|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Execute the destruction of the models immediately to ensure atomic cleanup.
|
2018-11-20 20:47:30 +05:30
|
|
|
success = ::Projects::DestroyService.new(project, current_user).execute
|
|
|
|
raise DestroyError, "Project #{project.id} can't be deleted" unless success
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
# reload the relation to prevent triggering destroy hooks on the projects again
|
2019-07-31 22:56:46 +05:30
|
|
|
group.projects.reset
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
group.children.each do |group|
|
|
|
|
# This needs to be synchronous since the namespace gets destroyed below
|
|
|
|
DestroyService.new(group, current_user).execute
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
group.chat_team&.remove_mattermost_team(current_user)
|
|
|
|
|
2020-04-15 14:45:12 +05:30
|
|
|
user_ids_for_project_authorizations_refresh = group.user_ids_for_project_authorizations
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
group.destroy
|
2020-04-15 14:45:12 +05:30
|
|
|
|
|
|
|
UserProjectAccessChangedService
|
|
|
|
.new(user_ids_for_project_authorizations_refresh)
|
|
|
|
.execute(blocking: true)
|
|
|
|
|
|
|
|
group
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Groups::DestroyService.prepend_if_ee('EE::Groups::DestroyService')
|