UX: Allow users to filter members on group page.

* Only admins are allowed to filter users by email.
This commit is contained in:
Guo Xiang Tan
2018-03-22 13:42:46 +08:00
parent 1cc0961566
commit f3b402ffd5
11 changed files with 171 additions and 25 deletions

View File

@ -159,6 +159,25 @@ class User < ActiveRecord::Base
scope :not_suspended, -> { where('suspended_till IS NULL OR suspended_till <= ?', Time.zone.now) }
scope :activated, -> { where(active: true) }
scope :filter_by_username, ->(filter) do
where('username_lower ILIKE ?', filter)
end
scope :filter_by_username_or_email, ->(filter) do
if filter =~ /.+@.+/
# probably an email so try the bypass
if user_id = UserEmail.where("lower(email) = ?", filter.downcase).pluck(:user_id).first
return where('users.id = ?', user_id)
end
end
joins(:primary_email)
.where(
'username_lower ILIKE :filter OR lower(user_emails.email) ILIKE :filter',
filter: "%#{filter}%"
)
end
module NewTopicDuration
ALWAYS = -1
LAST_VISIT = -2