Class: Organizations::Groups::TransferService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, Concerns::OrganizationUpdater
Defined in:
app/services/organizations/groups/transfer_service.rb

Constant Summary collapse

TransferError =
Class.new(StandardError)
BATCH_SIZE =
50

Constants included from Concerns::OrganizationUpdater

Concerns::OrganizationUpdater::ORGANIZATION_ID_UPDATE_BATCH_SIZE

Instance Method Summary collapse

Methods included from Concerns::OrganizationUpdater

#update_organization_id_for

Constructor Details

#initialize(group:, new_organization:, current_user:) ⇒ TransferService

Returns a new instance of TransferService.



12
13
14
15
16
# File 'app/services/organizations/groups/transfer_service.rb', line 12

def initialize(group:, new_organization:, current_user:)
  @group = group
  @new_organization = new_organization
  @current_user = current_user
end

Instance Method Details

#async_executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/organizations/groups/transfer_service.rb', line 18

def async_execute
  return ServiceResponse.error(message: transfer_error) unless can_transfer?

  Organizations::Groups::TransferWorker.perform_async(
    {
      'group_id' => group.id,
      'organization_id' => new_organization.id,
      'current_user_id' => current_user.id
    }
  )

  ServiceResponse.success(
    message: s_("TransferOrganization|Group transfer to organization initiated")
  )
end

#executeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/services/organizations/groups/transfer_service.rb', line 34

def execute
  return ServiceResponse.error(message: transfer_error) unless can_transfer?

  # Find or create bot users before transaction to avoid exclusive lease errors.
  # If the transaction is rolled back, new bots will still exist
  # but this does not affect data integrity
  user_transfer_service.prepare_bots

  Group.transaction do
    transfer_namespaces_and_projects
    transfer_users
  end

  log_transfer_success
  ServiceResponse.success
rescue StandardError => e
  log_transfer_error(e.message)
  ServiceResponse.error(message: e.message)
end