From 200ee15991911c393e217bc2b00ecd58f4132d4d Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 21 Sep 2015 16:27:47 -0700 Subject: [PATCH] FIX: Importer not handling usernames correctly --- script/import_scripts/base.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index 0bc796c73..039e4de83 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -258,9 +258,8 @@ class ImportScripts::Base if opts[:username].blank? || opts[:username].length < User.username_length.begin || opts[:username].length > User.username_length.end || - opts[:username] =~ /[^A-Za-z0-9_]/ || - opts[:username][0] =~ /[^A-Za-z0-9]/ || - !User.username_available?(opts[:username]) + !User.username_available?(opts[:username]) || + !UsernameValidator.new(opts[:username]).valid_format? opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email]) end opts[:email] = opts[:email].downcase @@ -289,13 +288,18 @@ class ImportScripts::Base if opts[:active] && opts[:password].present? u.activate end - rescue + rescue => e # try based on email - existing = User.find_by(email: opts[:email].downcase) - if existing - existing.custom_fields["import_id"] = import_id - existing.save! - u = existing + if e.record.errors.messages[:email].present? + existing = User.find_by(email: opts[:email].downcase) + if existing + existing.custom_fields["import_id"] = import_id + existing.save! + u = existing + end + else + puts "Error on record: #{opts}" + raise e end end post_create_action.try(:call, u) if u.persisted?