From 5a7f08067ae3a7ca8082dacedc0cf70c75b4520f Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 13 Nov 2025 18:58:51 -0500 Subject: [PATCH] Move setting Current.account into the middleware so that code called from the Rails controllers can use Current.account --- app/controllers/concerns/authentication.rb | 16 +++------------- config/initializers/tenanting/account_slug.rb | 1 + 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index f99af0083..f4ad6a013 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -35,10 +35,8 @@ module Authentication end def require_account - if request_account_id.blank? + unless Current.account.present? redirect_to session_menu_url(script_name: nil) - else - set_current_account end end @@ -57,7 +55,7 @@ module Authentication end def request_authentication - if request_account_id.present? + if Current.account.present? session[:return_to_after_authenticating] = request.url end @@ -73,7 +71,7 @@ module Authentication end def redirect_tenanted_request - redirect_to root_url if request_account_id + redirect_to root_url if Current.account.present? end def start_new_session_for(identity) @@ -92,12 +90,4 @@ module Authentication Current.session.destroy cookies.delete(:session_token) end - - def set_current_account - Current.account = Account.find_by(external_account_id: request_account_id) - end - - def request_account_id - request.env["fizzy.external_account_id"] - end end diff --git a/config/initializers/tenanting/account_slug.rb b/config/initializers/tenanting/account_slug.rb index edf67b383..74c400b1a 100644 --- a/config/initializers/tenanting/account_slug.rb +++ b/config/initializers/tenanting/account_slug.rb @@ -24,6 +24,7 @@ module AccountSlug # Stash the account's Queenbee ID. env["fizzy.external_account_id"] = AccountSlug.decode($2) + Current.account = Account.find_by(external_account_id: env["fizzy.external_account_id"]) end @app.call env