Class: Groups::ImportExport::ImportService

Inherits:
Object
  • Object
show all
Defined in:
app/services/groups/import_export/import_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group:, user:) ⇒ ImportService

Returns a new instance of ImportService.



8
9
10
11
12
13
14
# File 'app/services/groups/import_export/import_service.rb', line 8

def initialize(group:, user:)
  @group = group
  @current_user = user
  @user_role = user_role
  @shared = Gitlab::ImportExport::Shared.new(@group)
  @logger = Gitlab::Import::Logger.build
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def current_user
  @current_user
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def group
  @group
end

#sharedObject (readonly)

Returns the value of attribute shared.



6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def shared
  @shared
end

Instance Method Details

#async_executeObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/groups/import_export/import_service.rb', line 16

def async_execute
  group_import_state = GroupImportState.safe_find_or_create_by!(group: group, user: current_user)
  jid = GroupImportWorker.with_status.perform_async(current_user.id, group.id)

  if jid.present?
    group_import_state.update!(jid: jid)
  else
    group_import_state.fail_op('Failed to schedule import job')

    false
  end
end

#executeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/groups/import_export/import_service.rb', line 29

def execute
  Gitlab::Tracking.event(self.class.name, 'create', label: 'import_group_from_file')

  if valid_user_permissions? && import_file && valid_import_file? && restorers.all?(&:restore)
    notify_success

    Gitlab::Tracking.event(
      self.class.name,
      'create',
      label: 'import_access_level',
      user: current_user,
      extra: { user_role: user_role, import_type: 'import_group_from_file' }
    )

    group
  else
    notify_error!
  end

ensure
  remove_base_tmp_dir
  remove_import_file
end