forked from External/greenlight
Reduce number of roles queries for the admin controller (#631)
This commit is contained in:
committed by
farhatahmad
parent
5a3ad3159c
commit
8c63f793a5
@ -162,7 +162,7 @@ class AdminsController < ApplicationController
|
||||
private
|
||||
|
||||
def find_user
|
||||
@user = User.find_by!(uid: params[:user_uid])
|
||||
@user = User.where(uid: params[:user_uid]).includes(:roles).first
|
||||
end
|
||||
|
||||
def find_setting
|
||||
@ -176,10 +176,10 @@ class AdminsController < ApplicationController
|
||||
|
||||
# Gets the list of users based on your configuration
|
||||
def user_list
|
||||
initial_list = if current_user.has_role? :super_admin
|
||||
User.where.not(id: current_user.id)
|
||||
initial_list = if current_user.has_cached_role? :super_admin
|
||||
User.where.not(id: current_user.id).includes(:roles)
|
||||
else
|
||||
User.without_role(:super_admin).where.not(id: current_user.id)
|
||||
User.without_role(:super_admin).where.not(id: current_user.id).includes(:roles)
|
||||
end
|
||||
|
||||
list = @role.present? ? initial_list.with_role(@role.to_sym) : initial_list
|
||||
|
@ -116,7 +116,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# Checks to make sure that the admin has changed his password from the default
|
||||
def check_admin_password
|
||||
if current_user&.has_role?(:admin) && current_user&.greenlight_account? &&
|
||||
if current_user&.has_cached_role?(:admin) && current_user&.greenlight_account? &&
|
||||
current_user&.authenticate(Rails.configuration.admin_password_default)
|
||||
|
||||
flash.now[:alert] = I18n.t("default_admin",
|
||||
@ -156,10 +156,10 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# Checks if the user is banned and logs him out if he is
|
||||
def check_user_role
|
||||
if current_user&.has_role? :denied
|
||||
if current_user&.has_cached_role? :denied
|
||||
session.delete(:user_id)
|
||||
redirect_to root_path, flash: { alert: I18n.t("registration.banned.fail") }
|
||||
elsif current_user&.has_role? :pending
|
||||
elsif current_user&.has_cached_role? :pending
|
||||
session.delete(:user_id)
|
||||
redirect_to root_path, flash: { alert: I18n.t("registration.approval.fail") }
|
||||
end
|
||||
|
@ -274,7 +274,7 @@ class RoomsController < ApplicationController
|
||||
end
|
||||
|
||||
def verify_user_not_admin
|
||||
redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
|
||||
redirect_to admins_path if current_user && current_user&.has_cached_role?(:super_admin)
|
||||
end
|
||||
|
||||
def auth_required
|
||||
@ -287,7 +287,7 @@ class RoomsController < ApplicationController
|
||||
|
||||
# Does not apply to admin
|
||||
# 15+ option is used as unlimited
|
||||
return false if current_user&.has_role?(:admin) || limit == 15
|
||||
return false if current_user&.has_cached_role?(:admin) || limit == 15
|
||||
|
||||
current_user.rooms.count >= limit
|
||||
end
|
||||
|
@ -185,7 +185,7 @@ class UsersController < ApplicationController
|
||||
private
|
||||
|
||||
def find_user
|
||||
@user = User.find_by!(uid: params[:user_uid])
|
||||
@user = User.where(uid: params[:user_uid]).includes(:roles).first
|
||||
end
|
||||
|
||||
def ensure_unauthenticated
|
||||
|
Reference in New Issue
Block a user