Class: Organizations::Groups::TransferService
- Inherits:
-
Object
- Object
- Organizations::Groups::TransferService
- 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
- #async_execute ⇒ Object
- #execute ⇒ Object
-
#initialize(group:, new_organization:, current_user:) ⇒ TransferService
constructor
A new instance of TransferService.
Methods included from Concerns::OrganizationUpdater
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_execute ⇒ Object
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 |
#execute ⇒ Object
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.) ServiceResponse.error(message: e.) end |