Class: BulkImports::CreateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/bulk_imports/create_service.rb

Constant Summary collapse

ENTITY_TYPES_MAPPING =
{
  'group_entity' => 'groups',
  'project_entity' => 'projects'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params, credentials, fallback_organization:) ⇒ CreateService

Returns a new instance of CreateService.



38
39
40
41
42
43
# File 'app/services/bulk_imports/create_service.rb', line 38

def initialize(current_user, params, credentials, fallback_organization:)
  @current_user = current_user
  @fallback_organization = fallback_organization
  @params = params
  @credentials = credentials
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



36
37
38
# File 'app/services/bulk_imports/create_service.rb', line 36

def credentials
  @credentials
end

#current_userObject (readonly)

Returns the value of attribute current_user.



36
37
38
# File 'app/services/bulk_imports/create_service.rb', line 36

def current_user
  @current_user
end

#fallback_organizationObject (readonly)

Returns the value of attribute fallback_organization.



36
37
38
# File 'app/services/bulk_imports/create_service.rb', line 36

def fallback_organization
  @fallback_organization
end

#paramsObject (readonly)

Returns the value of attribute params.



36
37
38
# File 'app/services/bulk_imports/create_service.rb', line 36

def params
  @params
end

Instance Method Details

#executeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/services/bulk_imports/create_service.rb', line 45

def execute
  validate!

  bulk_import = create_bulk_import

  Gitlab::Tracking.event(
    self.class.name,
    'create',
    label: 'bulk_import_group',
    extra: { source_equals_destination: bulk_import.source_equals_destination? }
  )

  ::Import::BulkImports::EphemeralData.new(bulk_import.id).enable_importer_user_mapping
  ::Import::BulkImports::SourceUsersAttributesWorker.perform_async(bulk_import.id)

  BulkImportWorker.perform_async(bulk_import.id)

  ServiceResponse.success(payload: bulk_import)

rescue ActiveRecord::RecordInvalid, BulkImports::Error, BulkImports::NetworkError => e
  ServiceResponse.error(
    message: e.message,
    http_status: :unprocessable_entity
  )
end