Class: Groups::DestroyService

Inherits:
BaseService show all
Defined in:
app/services/groups/destroy_service.rb

Constant Summary collapse

DestroyError =
Class.new(StandardError)

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #group, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from Groups::BaseService

Instance Method Details

#async_executeObject



7
8
9
10
# File 'app/services/groups/destroy_service.rb', line 7

def async_execute
  job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
  Gitlab::AppLogger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
end

#executeObject

rubocop: disable CodeReuse/ActiveRecord

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/groups/destroy_service.rb', line 13

def execute
  # TODO - add a policy check here https://gitlab.com/gitlab-org/gitlab/-/issues/353082
  raise DestroyError, "You can't delete this group because you're blocked." if current_user.blocked?

  group.projects.includes(:project_feature).each do |project|
    # Execute the destruction of the models immediately to ensure atomic cleanup.
    success = ::Projects::DestroyService.new(project, current_user).execute

    raise DestroyError, "Project #{project.id} can't be deleted" unless success
  end

  # reload the relation to prevent triggering destroy hooks on the projects again
  group.projects.reset

  group.children.each do |group|
    # This needs to be synchronous since the namespace gets destroyed below
    DestroyService.new(group, current_user).execute
  end

  group.chat_team&.remove_mattermost_team(current_user)

  user_ids_for_project_authorizations_refresh = obtain_user_ids_for_project_authorizations_refresh

  destroy_group_bots

  group.destroy

  if user_ids_for_project_authorizations_refresh.present?
    UserProjectAccessChangedService
      .new(user_ids_for_project_authorizations_refresh)
      .execute
  end

  publish_event

  group
end