Check duplicate protocol name during import

This commit is contained in:
aignatov-bio 2020-05-27 12:10:48 +02:00
parent 4b7b3a8622
commit 40ad9fbf00

View file

@ -696,6 +696,26 @@ class TeamImporter
protocols_json.each do |protocol_json|
protocol = Protocol.new(protocol_json['protocol'])
orig_protocol_id = protocol.id
if protocol.name
protocol_name_unique = false
until protocol_name_unique
protocol_exist = if protocol.protocol_type == :in_repository_public
Protocol.where(protocol_type: protocol.protocol_type)
.where(team: team)
.find_by(name: protocol.name)
else
Protocol.where(protocol_type: protocol.protocol_type)
.where(team: team)
.where(added_by_id: find_user(protocol.added_by_id))
.find_by(name: protocol.name)
end
if protocol_exist
protocol.name = protocol.name + '(1)'
else
protocol_name_unique = true
end
end
end
protocol.id = nil
protocol.added_by_id = find_user(protocol.added_by_id)
protocol.team = team || my_module.experiment.project.team