Reduce number of roles queries for the admin controller (#631)

This commit is contained in:
shawn-higgins1
2019-07-15 14:45:06 -04:00
committed by farhatahmad
parent 5a3ad3159c
commit 8c63f793a5
10 changed files with 24 additions and 20 deletions

View File

@ -214,13 +214,17 @@ class User < ApplicationRecord
def admin_of?(user)
if Rails.configuration.loadbalanced_configuration
if has_role? :super_admin
# Pulls in the user roles if they weren't request in the original request
# So the has_cached_role? doesn't always return false
user.roles
if has_cached_role? :super_admin
id != user.id
else
(has_role? :admin) && (id != user.id) && (provider == user.provider) && (!user.has_role? :super_admin)
(has_cached_role? :admin) && (id != user.id) && (provider == user.provider) &&
(!user.has_cached_role? :super_admin)
end
else
((has_role? :admin) || (has_role? :super_admin)) && (id != user.id)
((has_cached_role? :admin) || (has_cached_role? :super_admin)) && (id != user.id)
end
end