forked from External/greenlight
Make all LIKE queries case insensitive (#2402)
This commit is contained in:
@ -54,6 +54,7 @@ class User < ApplicationRecord
|
||||
|
||||
class << self
|
||||
include AuthValues
|
||||
include Queries
|
||||
|
||||
# Generates a user from omniauth.
|
||||
def from_omniauth(auth)
|
||||
@ -69,48 +70,46 @@ class User < ApplicationRecord
|
||||
u.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.admins_search(string)
|
||||
return all if string.blank?
|
||||
def admins_search(string)
|
||||
return all if string.blank?
|
||||
|
||||
active_database = Rails.configuration.database_configuration[Rails.env]["adapter"]
|
||||
# Postgres requires created_at to be cast to a string
|
||||
created_at_query = if active_database == "postgresql"
|
||||
"created_at::text"
|
||||
else
|
||||
"created_at"
|
||||
like = like_text # Get the correct like clause to use based on db adapter
|
||||
|
||||
search_query = "users.name #{like} :search OR email #{like} :search OR username #{like} :search" \
|
||||
" OR users.#{created_at_text} #{like} :search OR users.provider #{like} :search" \
|
||||
" OR roles.name #{like} :search"
|
||||
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
end
|
||||
|
||||
search_query = "users.name LIKE :search OR email LIKE :search OR username LIKE :search" \
|
||||
" OR users.#{created_at_query} LIKE :search OR users.provider LIKE :search" \
|
||||
" OR roles.name LIKE :search"
|
||||
def admins_order(column, direction)
|
||||
# Arel.sql to avoid sql injection
|
||||
order(Arel.sql("users.#{column} #{direction}"))
|
||||
end
|
||||
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
end
|
||||
def shared_list_search(string)
|
||||
return all if string.blank?
|
||||
|
||||
def self.admins_order(column, direction)
|
||||
# Arel.sql to avoid sql injection
|
||||
order(Arel.sql("users.#{column} #{direction}"))
|
||||
end
|
||||
like = like_text # Get the correct like clause to use based on db adapter
|
||||
|
||||
def self.shared_list_search(string)
|
||||
return all if string.blank?
|
||||
search_query = "users.name #{like} :search OR users.uid #{like} :search"
|
||||
|
||||
search_query = "users.name LIKE :search OR users.uid LIKE :search"
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
end
|
||||
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
end
|
||||
def merge_list_search(string)
|
||||
return all if string.blank?
|
||||
|
||||
def self.merge_list_search(string)
|
||||
return all if string.blank?
|
||||
like = like_text # Get the correct like clause to use based on db adapter
|
||||
|
||||
search_query = "users.name LIKE :search OR users.email LIKE :search"
|
||||
search_query = "users.name #{like} :search OR users.email #{like} :search"
|
||||
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
search_param = "%#{sanitize_sql_like(string)}%"
|
||||
where(search_query, search: search_param)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a list of rooms ordered by last session (with nil rooms last)
|
||||
|
Reference in New Issue
Block a user