Class: Import::SourceUsers::GenerateCsvService

Inherits:
Object
  • Object
show all
Defined in:
app/services/import/source_users/generate_csv_service.rb

Overview

This class generates CSV data for Import::SourceUser records associated with a namespace. This spreadsheet is filled in and re-uploaded to facilitate the user mapping flow.

Constant Summary collapse

FILESIZE_LIMIT =

This is just to prevent any potential abuse. A test file with 20k rows comes in at 2.3MB. A 10MB file would be several tens of thousands, whereas we would rarely expect to exceed 10k rows.

10.megabytes
COLUMN_MAPPING =
{
  'Source host' => 'source_hostname',
  'Import type' => 'import_type',
  'Source user identifier' => 'source_user_identifier',
  'Source user name' => 'source_name',
  'Source username' => 'source_username',
  'GitLab username' => ->(_) { '' },
  'GitLab public email' => ->(_) { '' }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(namespace, current_user:) ⇒ GenerateCsvService

Returns a new instance of GenerateCsvService.

Parameters:

  • namespace (Namespace, Group)

    The namespace where the import source users are associated

  • current_user (User)

    The user performing the CSV export



26
27
28
29
# File 'app/services/import/source_users/generate_csv_service.rb', line 26

def initialize(namespace, current_user:)
  @namespace = namespace
  @current_user = current_user
end

Instance Method Details

#executeObject



31
32
33
34
35
36
37
38
# File 'app/services/import/source_users/generate_csv_service.rb', line 31

def execute
  # We use :owner_access here because it's shared between GroupPolicy and
  # NamespacePolicy.
  return error_invalid_permissions unless current_user.can?(:owner_access, namespace)
  return error_no_source_users if import_source_users.empty?

  ServiceResponse.success(payload: csv_data)
end