Move setting Current.account into the middleware
so that code called from the Rails controllers can use Current.account
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user