Commit f4d762d7 authored by James Lopez's avatar James Lopez
Browse files

addressing MR feedback, few changes to members mapper

parent 671756011139
......@@ -10,29 +10,18 @@ def initialize(exported_members:, user:, project:)
@project = project
@note_member_list = []
# This needs to run first, as second call would be from generate_map
# This needs to run first, as second call would be from #map
# which means project members already exist.
ensure_default_member!
end
def map
@map ||= generate_map
end
def default_user_id
@user.id
end
private
def generate_map
@map ||=
begin
@exported_members.inject(missing_keys_tracking_hash) do |hash, member|
existing_user = User.where(find_project_user_query(member)).first
old_user_id = member['user']['id']
if existing_user && add_user_as_team_member(existing_user, member).persisted?
if existing_user && add_user_as_team_member(existing_user, member)
hash[old_user_id] = existing_user.id
end
hash
......@@ -40,10 +29,16 @@ def generate_map
end
end
def default_user_id
@user.id
end
private
def missing_keys_tracking_hash
Hash.new do |_, key|
@note_member_list << key
@user.id
default_user_id
end
end
......@@ -54,7 +49,7 @@ def ensure_default_member!
def add_user_as_team_member(existing_user, member)
member['user'] = existing_user
ProjectMember.create(member_hash(member))
ProjectMember.create(member_hash(member)).persisted?
end
def member_hash(member)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment