FIX: Importer not handling usernames correctly

This commit is contained in:
Kane York 2015-09-21 16:27:47 -07:00
parent b6155889d5
commit 200ee15991

View file

@ -258,9 +258,8 @@ class ImportScripts::Base
if opts[:username].blank? || if opts[:username].blank? ||
opts[:username].length < User.username_length.begin || opts[:username].length < User.username_length.begin ||
opts[:username].length > User.username_length.end || opts[:username].length > User.username_length.end ||
opts[:username] =~ /[^A-Za-z0-9_]/ || !User.username_available?(opts[:username]) ||
opts[:username][0] =~ /[^A-Za-z0-9]/ || !UsernameValidator.new(opts[:username]).valid_format?
!User.username_available?(opts[:username])
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email]) opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email])
end end
opts[:email] = opts[:email].downcase opts[:email] = opts[:email].downcase
@ -289,13 +288,18 @@ class ImportScripts::Base
if opts[:active] && opts[:password].present? if opts[:active] && opts[:password].present?
u.activate u.activate
end end
rescue rescue => e
# try based on email # try based on email
existing = User.find_by(email: opts[:email].downcase) if e.record.errors.messages[:email].present?
if existing existing = User.find_by(email: opts[:email].downcase)
existing.custom_fields["import_id"] = import_id if existing
existing.save! existing.custom_fields["import_id"] = import_id
u = existing existing.save!
u = existing
end
else
puts "Error on record: #{opts}"
raise e
end end
end end
post_create_action.try(:call, u) if u.persisted? post_create_action.try(:call, u) if u.persisted?