mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 00:33:36 +02:00
Merge branch '105046446-users_import' into staging
This commit is contained in:
commit
af6f63f0a1
1 changed files with 43 additions and 35 deletions
|
@ -128,61 +128,69 @@ namespace :import do
|
||||||
desc 'Import users'
|
desc 'Import users'
|
||||||
task users: :environment do
|
task users: :environment do
|
||||||
start = Time.zone.now.to_f
|
start = Time.zone.now.to_f
|
||||||
puts '-----> Importing users...'
|
puts "-----> Importing users and IP's..."
|
||||||
|
|
||||||
|
id_users = []
|
||||||
users = []
|
users = []
|
||||||
ips = []
|
ips = []
|
||||||
|
temp = []
|
||||||
|
|
||||||
existing_ids = ApiUser.pluck(:legacy_id)
|
existing_ids = ApiUser.pluck(:legacy_id)
|
||||||
|
existing_ips = WhiteIp.pluck(:ipv4)
|
||||||
count = 0
|
|
||||||
|
|
||||||
Legacy::Registrar.all.each do |x|
|
Legacy::Registrar.all.each do |x|
|
||||||
|
|
||||||
next if existing_ids.include?(x.id)
|
x.acl.all.each do |y|
|
||||||
count += 1
|
|
||||||
|
|
||||||
if x.acl.last.try(:cert) != 'pki'
|
next if existing_ids.include?(y.id)
|
||||||
if x.acl.last.try(:cert) != 'idkaart'
|
|
||||||
users << ApiUser.new({
|
|
||||||
username: x.handle.try(:strip),
|
|
||||||
password: x.acl.last.try(:password) ? x.acl.last.try(:password) : ('a'..'z').to_a.shuffle.first(8).join,
|
|
||||||
identity_code: x.handle.try(:strip),
|
|
||||||
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
|
||||||
roles: ['epp'],
|
|
||||||
legacy_id: x.try(:id)
|
|
||||||
})
|
|
||||||
elsif x.acl.last.try(:cert) == 'idkaart'
|
|
||||||
users << ApiUser.new({
|
|
||||||
username: x.acl.last.try(:password) ? x.acl.last.try(:password) : x.acl.first.try(:password),
|
|
||||||
password: ('a'..'z').to_a.shuffle.first(8).join,
|
|
||||||
identity_code: x.acl.last.try(:password) ? x.acl.last.try(:password) : x.acl.first.try(:password),
|
|
||||||
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
|
||||||
roles: ['billing'],
|
|
||||||
legacy_id: x.try(:id)
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
existing_ips = WhiteIp.pluck(:ipv4)
|
if y.try(:cert) != 'pki'
|
||||||
|
|
||||||
x.acl.all.each do |y|
|
if y.try(:cert) == 'idkaart'
|
||||||
next if existing_ips.include?(y.ipaddr)
|
id_users << ApiUser.new({
|
||||||
if !y.ipaddr.nil? && y.ipaddr != ''
|
username: y.try(:password) ? y.try(:password) : y.try(:password),
|
||||||
ips << WhiteIp.new({
|
password: ('a'..'z').to_a.shuffle.first(8).join,
|
||||||
|
identity_code: y.try(:password) ? y.try(:password) : y.try(:password),
|
||||||
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
||||||
ipv4: y.ipaddr,
|
roles: ['billing'],
|
||||||
interfaces: ['api', 'registrar']
|
legacy_id: y.try(:id)
|
||||||
})
|
})
|
||||||
|
else
|
||||||
|
temp << ApiUser.new({
|
||||||
|
username: x.handle.try(:strip),
|
||||||
|
password: y.try(:password) ? y.try(:password) : ('a'..'z').to_a.shuffle.first(8).join,
|
||||||
|
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
||||||
|
roles: ['epp'],
|
||||||
|
legacy_id: y.try(:id)
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
temp = temp.reverse!.uniq{|u| u.username }
|
||||||
|
end
|
||||||
|
users = temp
|
||||||
|
|
||||||
|
x.acl.all.each do |y|
|
||||||
|
next if existing_ips.include?(y.ipaddr)
|
||||||
|
if !y.ipaddr.nil? && y.ipaddr != ''
|
||||||
|
ips << WhiteIp.new({
|
||||||
|
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
|
||||||
|
ipv4: y.ipaddr,
|
||||||
|
interfaces: ['api', 'registrar']
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ApiUser.import id_users, validate: false
|
||||||
ApiUser.import users, validate: false
|
ApiUser.import users, validate: false
|
||||||
|
|
||||||
if ips
|
if ips
|
||||||
WhiteIp.import ips, validate: false
|
WhiteIp.import ips, validate: false
|
||||||
end
|
end
|
||||||
puts "-----> Imported #{count} new users in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
|
||||||
|
puts "-----> Imported #{id_users.count} billing users and #{users.count} epp users"
|
||||||
|
puts "-----> Imported #{ips.count} white IP's in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Import contacts'
|
desc 'Import contacts'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue