DEV: Simplify username validation in base importer

DEV: Simplify username validation in base importer

The UsernameValidator does already all the hard work. No need to do any additional checks in the import script. The checks were out-of-date anyway.

diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb
index b149ac7..1959566 100644
--- a/script/import_scripts/base.rb
+++ b/script/import_scripts/base.rb
@@ -299,16 +299,8 @@ class ImportScripts::Base
     original_name = opts[:name]
     original_email = opts[:email] = opts[:email].downcase
 
-    # Allow the || operations to work with empty strings ''
-    opts[:username] = nil if opts[:username].blank?
-
-    if opts[:username].blank? ||
-      opts[:username].length < User.username_length.begin ||
-      opts[:username].length > User.username_length.end ||
-      !User.username_available?(opts[:username]) ||
-      !UsernameValidator.new(opts[:username]).valid_format?
-
-      opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name].presence || opts[:email])
+    if !UsernameValidator.new(opts[:username]).valid_format? || !User.username_available?(opts[:username])
+      opts[:username] = UserNameSuggester.suggest(opts[:username].presence || opts[:name].presence || opts[:email])
     end
 
     unless opts[:email][EmailValidator.email_regex]

GitHub sha: b48ca9de

1 Like