Class: Gitlab::ImportExport::MembersMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import_export/members_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(exported_members:, user:, importable:) ⇒ MembersMapper

Returns a new instance of MembersMapper.


6
7
8
9
10
11
12
13
14
# File 'lib/gitlab/import_export/members_mapper.rb', line 6

def initialize(exported_members:, user:, importable:)
  @exported_members = user.admin? ? exported_members : []
  @user = user
  @importable = importable

  # This needs to run first, as second call would be from #map
  # which means Project/Group members already exist.
  ensure_default_member!
end

Instance Method Details

#default_user_idObject


33
34
35
# File 'lib/gitlab/import_export/members_mapper.rb', line 33

def default_user_id
  @user.id
end

#include?(old_author_id) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/gitlab/import_export/members_mapper.rb', line 37

def include?(old_author_id)
  map.has_key?(old_author_id) && map[old_author_id] != default_user_id
end

#mapObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/import_export/members_mapper.rb', line 16

def map
  @map ||=
    begin
      @exported_members.inject(missing_keys_tracking_hash) do |hash, member|
        if member['user']
          old_user_id = member['user']['id']
          existing_user = User.find_by(find_user_query(member))
          hash[old_user_id] = existing_user.id if existing_user && add_team_member(member, existing_user)
        else
          add_team_member(member)
        end

        hash
      end
    end
end