mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-31 04:32:06 +08:00
Check duplicate protocol name during import
This commit is contained in:
parent
4b7b3a8622
commit
40ad9fbf00
1 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue