forked from External/greenlight
GRN2-xx: Cleaned up manage users query (#1786)
* Cleaned up manage users query * Bring back filter by role
This commit is contained in:
@ -37,9 +37,8 @@ class AdminsController < ApplicationController
|
||||
@search = params[:search] || ""
|
||||
@order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
|
||||
@order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"
|
||||
|
||||
@role = params[:role] ? Role.find_by(name: params[:role], provider: @user_domain) : nil
|
||||
@tab = params[:tab] || "active"
|
||||
@role = params[:role] ? Role.find_by(name: params[:role], provider: @user_domain) : nil
|
||||
|
||||
@user_list = merge_user_list
|
||||
|
||||
|
@ -21,25 +21,27 @@ module Populator
|
||||
|
||||
# Returns a list of users that are in the same context of the current user
|
||||
def manage_users_list
|
||||
current_role = @role
|
||||
|
||||
initial_list = case @tab
|
||||
when "active"
|
||||
User.without_role([:pending, :denied])
|
||||
when "deleted"
|
||||
User.deleted
|
||||
when "pending"
|
||||
User.with_role(:pending)
|
||||
when "denied"
|
||||
User.with_role(:denied)
|
||||
else
|
||||
User.all
|
||||
end
|
||||
|
||||
current_role = Role.find_by(name: @tab, provider: @user_domain) if @tab == "pending" || @tab == "denied"
|
||||
initial_list = initial_list.with_role(@role.name) if @role.present?
|
||||
|
||||
initial_list = initial_list.without_role(:super_admin) unless current_user.has_role? :super_admin
|
||||
|
||||
initial_list = initial_list.where(provider: @user_domain) if Rails.configuration.loadbalanced_configuration
|
||||
|
||||
initial_list.where.not(id: current_user.id)
|
||||
.admins_search(@search, current_role)
|
||||
.admins_search(@search)
|
||||
.admins_order(@order_column, @order_direction)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user