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

@ -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