debian-mirror-gitlab/app/services/groups/destroy_service.rb

62 lines
2.1 KiB
Ruby
Raw Normal View History

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)
2021-03-08 18:12:59 +05:30
# If any other groups are shared with the group that is being destroyed,
# we should specifically trigger update of all project authorizations
2021-04-17 20:07:23 +05:30
# for users that are the direct members of this group.
2021-03-08 18:12:59 +05:30
# If not, the project authorization records of these users to projects within the shared groups
# will never be removed, causing inconsistencies with access permissions.
if any_other_groups_are_shared_with_this_group?
2021-04-17 20:07:23 +05:30
user_ids_for_project_authorizations_refresh = group.users_ids_of_direct_members
2021-03-08 18:12:59 +05:30
end
2020-04-15 14:45:12 +05:30
2018-03-17 18:26:18 +05:30
group.destroy
2020-04-15 14:45:12 +05:30
2021-03-08 18:12:59 +05:30
if user_ids_for_project_authorizations_refresh.present?
UserProjectAccessChangedService
.new(user_ids_for_project_authorizations_refresh)
.execute(blocking: true)
end
2020-04-15 14:45:12 +05:30
group
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2021-03-08 18:12:59 +05:30
private
def any_other_groups_are_shared_with_this_group?
group.shared_group_links.any?
end
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')