1 2 3 4 5 6 7 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 44 45 46 47 48 49 50
|
# frozen_string_literal: true
# This class is used by Gitlab::ImportExport::Base::RelationFactory when mapping
# users from the source to the destination.
#
# It is required that Import::SourceUser objects with source_user_identifier exists
# before executing Gitlab::ImportExport::Base::RelationFactory. The latter class was
# not modified to create Import::SourceUser if it does not exist since the class is
# also used by file based imports.
module Import
module BulkImports
class SourceUsersMapper
include Gitlab::Utils::StrongMemoize
# Gitlab::ImportExport::Base::RelationFactory expects member_mapper#map to
# return an object that responds to []. For the other mappers a hash is
# returned. In this case SourceUsersMapper#map returns a class that responds
# to [].
class MockedHash
def initialize(source_user_mapper)
@source_user_mapper = source_user_mapper
end
def [](user_identifier)
@source_user_mapper.find_source_user(user_identifier).mapped_user_id
end
end
def initialize(context:)
@context = context
end
def map
@map ||= MockedHash.new(source_user_mapper)
end
# Import::SourceUser with the respective user_identifier will always
# exist since they are created beforehand.
def include?(_user_identifier)
true
end
private
attr_reader :context
delegate :source_user_mapper, to: :context
end
end
end
|