From b48ca9dee95931bea75f804be95cf134bbd2fc00 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 1 Oct 2019 20:32:41 +0200 Subject: [PATCH] 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. --- script/import_scripts/base.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index b149ac780a1..1959566c174 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]