mirror of
https://github.com/discourse/discourse.git
synced 2025-08-21 19:11:18 +08:00
fix the build :fired:
This commit is contained in:
parent
2c38f969cc
commit
a609e1b655
1 changed files with 55 additions and 57 deletions
|
@ -26,73 +26,71 @@ class AdminUserIndexQuery
|
||||||
find_users_query.count
|
find_users_query.count
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def initialize_query_with_order(klass)
|
||||||
|
order = [params[:order]]
|
||||||
|
|
||||||
def initialize_query_with_order(klass)
|
if params[:query] == "active"
|
||||||
order = [params[:order]]
|
order << "COALESCE(last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD')) DESC"
|
||||||
|
else
|
||||||
|
order << "created_at DESC"
|
||||||
|
end
|
||||||
|
|
||||||
if params[:query] == "active"
|
order << "username"
|
||||||
order << "COALESCE(last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD')) DESC"
|
|
||||||
|
klass.order(order.reject(&:blank?).join(","))
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_by_trust
|
||||||
|
levels = trust_levels.map { |key, _| key.to_s }
|
||||||
|
if levels.include?(params[:query])
|
||||||
|
@query.where('trust_level = ?', trust_levels[params[:query].to_sym])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_by_query_classification
|
||||||
|
case params[:query]
|
||||||
|
when 'admins' then @query.where(admin: true)
|
||||||
|
when 'moderators' then @query.where(moderator: true)
|
||||||
|
when 'blocked' then @query.blocked
|
||||||
|
when 'suspended' then @query.suspended
|
||||||
|
when 'pending' then @query.not_suspended.where(approved: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_by_search
|
||||||
|
if params[:filter].present?
|
||||||
|
if ip = IPAddr.new(params[:filter]) rescue nil
|
||||||
|
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
|
||||||
else
|
else
|
||||||
order << "created_at DESC"
|
@query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%")
|
||||||
end
|
|
||||||
|
|
||||||
order << "username"
|
|
||||||
|
|
||||||
klass.order(order.reject(&:blank?).join(","))
|
|
||||||
end
|
|
||||||
|
|
||||||
def filter_by_trust
|
|
||||||
levels = trust_levels.map { |key, _| key.to_s }
|
|
||||||
if levels.include?(params[:query])
|
|
||||||
@query.where('trust_level = ?', trust_levels[params[:query].to_sym])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def filter_by_query_classification
|
def filter_by_ip
|
||||||
case params[:query]
|
if params[:ip].present?
|
||||||
when 'admins' then @query.where(admin: true)
|
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip])
|
||||||
when 'moderators' then @query.where(moderator: true)
|
|
||||||
when 'blocked' then @query.blocked
|
|
||||||
when 'suspended' then @query.suspended
|
|
||||||
when 'pending' then @query.not_suspended.where(approved: false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def filter_by_search
|
def filter_exclude
|
||||||
if params[:filter].present?
|
if params[:exclude].present?
|
||||||
if ip = IPAddr.new(params[:filter]) rescue nil
|
@query.where('id != ?', params[:exclude])
|
||||||
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
|
|
||||||
else
|
|
||||||
@query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def filter_by_ip
|
# this might not be needed in rails 4 ?
|
||||||
if params[:ip].present?
|
def append(active_relation)
|
||||||
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip])
|
@query = active_relation if active_relation
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def filter_exclude
|
def find_users_query
|
||||||
if params[:exclude].present?
|
append filter_by_trust
|
||||||
@query.where('id != ?', params[:exclude])
|
append filter_by_query_classification
|
||||||
end
|
append filter_by_ip
|
||||||
end
|
append filter_exclude
|
||||||
|
append filter_by_search
|
||||||
# this might not be needed in rails 4 ?
|
@query
|
||||||
def append(active_relation)
|
end
|
||||||
@query = active_relation if active_relation
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_users_query
|
|
||||||
append filter_by_trust
|
|
||||||
append filter_by_query_classification
|
|
||||||
append filter_by_ip
|
|
||||||
append filter_exclude
|
|
||||||
append filter_by_search
|
|
||||||
@query
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue