Handle nil and blank cases in Account finders (#3500)
This commit is contained in:
		@@ -37,21 +37,25 @@ module AccountFinderConcern
 | 
			
		||||
 | 
			
		||||
    def scoped_accounts
 | 
			
		||||
      Account.unscoped.tap do |scope|
 | 
			
		||||
        scope.merge! with_usernames
 | 
			
		||||
        scope.merge! matching_username
 | 
			
		||||
        scope.merge! matching_domain
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def with_usernames
 | 
			
		||||
      Account.where.not(username: [nil, ''])
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def matching_username
 | 
			
		||||
      raise(ActiveRecord::RecordNotFound) if username.blank?
 | 
			
		||||
      Account.where(Account.arel_table[:username].lower.eq username.downcase)
 | 
			
		||||
      Account.where(Account.arel_table[:username].lower.eq username.to_s.downcase)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def matching_domain
 | 
			
		||||
      if domain.nil?
 | 
			
		||||
        Account.where(domain: nil)
 | 
			
		||||
      else
 | 
			
		||||
        Account.where(Account.arel_table[:domain].lower.eq domain.downcase)
 | 
			
		||||
        Account.where(Account.arel_table[:domain].lower.eq domain.to_s.downcase)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user