From 54234ef54bda8337f90708e254f20a44ce10d430 Mon Sep 17 00:00:00 2001 From: Ahmad Farhat Date: Mon, 24 Feb 2020 17:30:39 -0500 Subject: [PATCH] Admins that are not signed in are redirected to the signin page when doing admin actions (#964) --- app/controllers/application_controller.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bc45b8eb..ddc07cdf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -200,7 +200,23 @@ class ApplicationController < ActionController::Base # Manually deal with 401 errors rescue_from CanCan::AccessDenied do |_exception| - render "errors/greenlight_error" + if current_user + render "errors/greenlight_error" + else + # Store the current url as a cookie to redirect to after sigining in + cookies[:return_to] = request.url + + # Get the correct signin path + path = if allow_greenlight_accounts? + signin_path + elsif Rails.configuration.loadbalanced_configuration + omniauth_login_url(:bn_launcher) + else + signin_path + end + + redirect_to path + end end private