Class: Import::BulkImports::Common::Transformers::SourceUserMemberAttributesTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/import/bulk_imports/common/transformers/source_user_member_attributes_transformer.rb

Instance Method Summary collapse

Instance Method Details

#transform(context, data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/import/bulk_imports/common/transformers/source_user_member_attributes_transformer.rb', line 8

def transform(context, data)
  return data if !context.importer_user_mapping_enabled? || data.nil?

  # user is nil for pending member invitations
  return unless data['user']

  # Create source_user and placeholder user if they do not exists so
  # they can be mapped to contributions in subsequent pipelines
  source_user = find_or_create_source_user(context, data)

  access_level = data.dig('access_level', 'integer_value')
  return unless valid_access_level?(access_level)

  if source_user.accepted_status?
    # We don't want to create a new membership for a project bot,
    # as they are not allowed to be members of other groups or projects.
    return if source_user.mapped_user.project_bot?

    {
      user_id: source_user.mapped_user_id,
      access_level: access_level,
      created_at: data['created_at'],
      updated_at: data['updated_at'],
      expires_at: data['expires_at'],
      created_by_id: context.current_user.id
    }
  else
    {
      source_user: source_user,
      access_level: access_level,
      expires_at: data['expires_at'],
      group: context.entity.group,
      project: context.entity.project
    }
  end
end