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) ⇒ CreateService

Returns a new instance of CreateService.



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

def initialize(current_user, params, credentials)
  @current_user = current_user
  @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

#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



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

def execute
  validate!

  bulk_import = create_bulk_import

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

  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