few more changes based on feedback
This commit is contained in:
parent
f4d762d7c2
commit
833dc3204d
|
@ -2,13 +2,13 @@ module Gitlab
|
|||
module ImportExport
|
||||
class MembersMapper
|
||||
|
||||
attr_reader :note_member_list
|
||||
attr_reader :missing_author_ids
|
||||
|
||||
def initialize(exported_members:, user:, project:)
|
||||
@exported_members = exported_members
|
||||
@user = user
|
||||
@project = project
|
||||
@note_member_list = []
|
||||
@missing_author_ids = []
|
||||
|
||||
# This needs to run first, as second call would be from #map
|
||||
# which means project members already exist.
|
||||
|
@ -37,7 +37,7 @@ module Gitlab
|
|||
|
||||
def missing_keys_tracking_hash
|
||||
Hash.new do |_, key|
|
||||
@note_member_list << key
|
||||
@missing_author_ids << key
|
||||
default_user_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,21 +67,30 @@ module Gitlab
|
|||
project
|
||||
end
|
||||
|
||||
# Given a relation hash containing one or more models and its relationships,
|
||||
# loops through each model and each object from a model type and
|
||||
# and assigns its correspondent attributes hash from +tree_hash+
|
||||
# Example:
|
||||
# +relation_key+ issues, loops through the list of *issues* and for each individual
|
||||
# issue, finds any subrelations such as notes, creates them and assign them back to the hash
|
||||
def create_sub_relations(relation, tree_hash)
|
||||
relation_key = relation.keys.first.to_s
|
||||
tree_hash[relation_key].each do |relation_item|
|
||||
relation.values.flatten.each do |sub_relation|
|
||||
relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation)
|
||||
relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assign_relation_hash(relation_item, sub_relation)
|
||||
if sub_relation.is_a?(Hash)
|
||||
relation_hash = relation_item[sub_relation.keys.first.to_s]
|
||||
sub_relation = sub_relation.keys.first
|
||||
else
|
||||
relation_hash = relation_item[sub_relation.to_s]
|
||||
end
|
||||
|
||||
relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank?
|
||||
end
|
||||
end
|
||||
return relation_hash, sub_relation
|
||||
end
|
||||
|
||||
def create_relation(relation, relation_hash_list)
|
||||
|
@ -89,7 +98,7 @@ module Gitlab
|
|||
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
|
||||
relation_hash: relation_hash.merge('project_id' => project.id),
|
||||
members_mapper: members_mapper,
|
||||
user_admin: @user.is_admin?)
|
||||
user: @user)
|
||||
end
|
||||
|
||||
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
|
||||
|
|
|
@ -16,11 +16,11 @@ module Gitlab
|
|||
new(*args).create
|
||||
end
|
||||
|
||||
def initialize(relation_sym:, relation_hash:, members_mapper:, user_admin:)
|
||||
def initialize(relation_sym:, relation_hash:, members_mapper:, user:)
|
||||
@relation_name = OVERRIDES[relation_sym] || relation_sym
|
||||
@relation_hash = relation_hash.except('id', 'noteable_id')
|
||||
@members_mapper = members_mapper
|
||||
@user_admin = user_admin
|
||||
@user = user
|
||||
end
|
||||
|
||||
# Creates an object from an actual model with name "relation_sym" with params from
|
||||
|
@ -57,7 +57,7 @@ module Gitlab
|
|||
|
||||
author = @relation_hash.delete('author')
|
||||
|
||||
if admin_user? && @members_mapper.note_member_list.include?(old_author_id)
|
||||
if admin_user? && @members_mapper.missing_author_ids.include?(old_author_id)
|
||||
update_note_for_missing_author(author['name'])
|
||||
end
|
||||
end
|
||||
|
@ -119,7 +119,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def admin_user?
|
||||
@user_admin
|
||||
@user.is_admin?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
|
|||
it 'updates missing author IDs on missing project member' do
|
||||
members_mapper.map[-1]
|
||||
|
||||
expect(members_mapper.note_member_list.first).to eq(-1)
|
||||
expect(members_mapper.missing_author_ids.first).to eq(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue