Skip to content

Commit

Permalink
Introduce User#lower_userid to avoid arel
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jan 7, 2021
1 parent 4d11d89 commit c30555a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/authenticator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def failure_reason(_username, _request)

def case_insensitive_find_by_userid(username)
user = User.lookup_by_userid(username)
user || User.in_my_region.where('lower(userid) = ?', username.downcase).order(:lastlogon).last
user || User.in_my_region.where(:lower_userid => username.downcase).order(:lastlogon).last
end

def userid_for(_identity, username)
Expand Down
9 changes: 8 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def self.lookup_by_lower_email(email, cache = [])
singleton_class.send(:alias_method, :find_by_lower_email, :lookup_by_lower_email)
Vmdb::Deprecation.deprecate_methods(singleton_class, :find_by_lower_email => :lookup_by_lower_email)

def lower_userid
userid&.downcase
end

virtual_attribute :lower_userid, :string, :arel => ->(t) { t.grouping(t[:userid].lower) }
hide_attribute :lower_userid

virtual_column :ldap_group, :type => :string, :uses => :current_group
# FIXME: amazon_group too?
virtual_column :miq_group_description, :type => :string, :uses => :current_group
Expand Down Expand Up @@ -333,7 +340,7 @@ def regional_users
end

def self.regional_users(user)
where(arel_table.grouping(Arel::Nodes::NamedFunction.new("LOWER", [arel_attribute(:userid)]).eq(user.userid.downcase)))
where(:lower_userid => user.userid.downcase)
end

def self.super_admin
Expand Down
2 changes: 1 addition & 1 deletion lib/token_store/sql_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def session_key(token)
end

def find_user_by_userid(userid)
User.in_my_region.where('lower(userid) = ?', userid.downcase).first
User.in_my_region.where(:lower_userid => userid.downcase).first
end

def find_user_by_id(id)
Expand Down
2 changes: 1 addition & 1 deletion tools/miq_config_sssd_ldap/configure_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def dn_to_upn(userid)

def find_user(userid)
user = User.lookup_by_userid(userid)
user || User.in_my_region.where('lower(userid) = ?', userid).order(:lastlogon).last
user || User.in_my_region.where(:lower_userid => userid).order(:lastlogon).last
end
end
end

0 comments on commit c30555a

Please sign in to comment.