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.
This commit is contained in:
Gerhard Schlager 2019-10-01 20:32:41 +02:00
parent 9e4fb262cf
commit b48ca9dee9
1 changed files with 2 additions and 10 deletions

View File

@ -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]