Read about our upcoming Code of Conduct on this issue

destroy_group_service.rb 904 Bytes
Newer Older
1
2
3
4
5
6
7
class DestroyGroupService
  attr_accessor :group, :current_user

  def initialize(group, user)
    @group, @current_user = group, user
  end

8
  def async_execute
9
10
11
12
    # Soft delete via paranoia gem
    group.destroy
    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}")
13
14
  end

15
  def execute
16
    group.projects.each do |project|
17
      # Execute the destruction of the models immediately to ensure atomic cleanup.
18
      # Skip repository removal because we remove directory with namespace
19
20
      # that contain all these repositories
      ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
21
22
    end

23
24
25
26
    group.children.each do |group|
      DestroyGroupService.new(group, current_user).async_execute
    end

27
    group.really_destroy!
28
29
  end
end