From 8e13ce5b78bae36f1f88df9dd98bb43cd4120320 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 20 Jul 2025 13:00:09 -0400 Subject: [PATCH] Drop Current.account and just use Account.sole I had reintroduced this in dacb53b8 after David removed it in 6bbf68a4, but now I agree we don't need it. Also, fix a CORS error when trying to redirect a user to an untenanted path after login (see https://fizzy.37signals.com/5986089/collections/2/cards/1032). --- app/controllers/concerns/authentication.rb | 19 ++++++++----------- .../sessions/launchpad_controller.rb | 2 +- app/models/current.rb | 1 - app/views/users/new.html.erb | 2 +- db/seeds.rb | 2 +- script/bootstrap-signal-id.rb | 6 +++--- script/closureulate/collections_and_cards.rb | 2 +- script/create-accounts-in-staging.rb | 2 +- script/migrate-content-to-slugged-urls.rb | 4 ++-- script/populate/cards_for_pagination.rb | 2 +- script/rename-tenants-to-qb-account-id.rb | 2 +- 11 files changed, 20 insertions(+), 24 deletions(-) diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index db21f5c7e..e6d3b7ddd 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -5,7 +5,6 @@ module Authentication # Checking for tenant must happen first so we redirect before trying to access the db. before_action :require_tenant - before_action :set_current_account before_action :require_authentication helper_method :authenticated? end @@ -23,7 +22,6 @@ module Authentication def require_untenanted_access(**options) skip_before_action :require_tenant, **options - skip_before_action :set_current_account, **options skip_before_action :require_authentication, **options before_action :redirect_tenanted_request, **options end @@ -52,11 +50,14 @@ module Authentication Session.find_signed(cookies.signed[:session_token]) end - - def request_authentication - session[:return_to_after_authenticating] = request.url - - redirect_to Launchpad.login_url(product: true, account: Current.account), allow_other_host: true + def request_authentication(untenanted: false) + if ApplicationRecord.current_tenant.present? + session[:return_to_after_authenticating] = request.url + redirect_to Launchpad.login_url(product: true, account: Account.sole), allow_other_host: true + else + # Don't save the current untenanted URL, because it's just going to bounce back to Launchpad after login anyway. + redirect_to Launchpad.login_url(product: true), allow_other_host: true + end end def after_authentication_url @@ -83,10 +84,6 @@ module Authentication cookies.signed.permanent[:session_token] = { value: session.signed_id, httponly: true, same_site: :lax } end - def set_current_account - Current.account = Account.first - end - def terminate_session Current.session.destroy cookies.delete(:session_token) diff --git a/app/controllers/sessions/launchpad_controller.rb b/app/controllers/sessions/launchpad_controller.rb index 1844b6133..7cfbf2a06 100644 --- a/app/controllers/sessions/launchpad_controller.rb +++ b/app/controllers/sessions/launchpad_controller.rb @@ -7,7 +7,7 @@ class Sessions::LaunchpadController < ApplicationController end def update - user = Current.account.signal_account.authenticate(sig: @sig).try(:peer) + user = Account.sole.signal_account.authenticate(sig: @sig).try(:peer) if user.present? && user.active? start_new_session_for user redirect_to after_authentication_url diff --git a/app/models/current.rb b/app/models/current.rb index 5a85b2e16..f67ef117d 100644 --- a/app/models/current.rb +++ b/app/models/current.rb @@ -1,7 +1,6 @@ class Current < ActiveSupport::CurrentAttributes attribute :session attribute :http_method, :request_id, :user_agent, :ip_address, :referrer - attribute :account delegate :user, to: :session, allow_nil: true end diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index e943075bc..f7d407389 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -4,7 +4,7 @@