Merge pull request #772 from basecamp/flavorjones/unwind-current-account

Drop Current.account and just use Account.sole
This commit is contained in:
Mike Dalessio
2025-07-20 13:13:00 -04:00
committed by GitHub
12 changed files with 22 additions and 24 deletions
+2
View File
@@ -16,6 +16,7 @@
/tmp/* /tmp/*
!/log/.keep !/log/.keep
!/tmp/.keep !/tmp/.keep
*.log
# Ignore pidfiles, but keep the directory. # Ignore pidfiles, but keep the directory.
/tmp/pids/* /tmp/pids/*
@@ -28,6 +29,7 @@
/tmp/storage/* /tmp/storage/*
!/tmp/storage/ !/tmp/storage/
!/tmp/storage/.keep !/tmp/storage/.keep
/data
/public/assets /public/assets
+8 -11
View File
@@ -5,7 +5,6 @@ module Authentication
# Checking for tenant must happen first so we redirect before trying to access the db. # Checking for tenant must happen first so we redirect before trying to access the db.
before_action :require_tenant before_action :require_tenant
before_action :set_current_account
before_action :require_authentication before_action :require_authentication
helper_method :authenticated? helper_method :authenticated?
end end
@@ -23,7 +22,6 @@ module Authentication
def require_untenanted_access(**options) def require_untenanted_access(**options)
skip_before_action :require_tenant, **options skip_before_action :require_tenant, **options
skip_before_action :set_current_account, **options
skip_before_action :require_authentication, **options skip_before_action :require_authentication, **options
before_action :redirect_tenanted_request, **options before_action :redirect_tenanted_request, **options
end end
@@ -52,11 +50,14 @@ module Authentication
Session.find_signed(cookies.signed[:session_token]) Session.find_signed(cookies.signed[:session_token])
end end
def request_authentication(untenanted: false)
def request_authentication if ApplicationRecord.current_tenant.present?
session[:return_to_after_authenticating] = request.url session[:return_to_after_authenticating] = request.url
redirect_to Launchpad.login_url(product: true, account: Account.sole), allow_other_host: true
redirect_to Launchpad.login_url(product: true, account: Current.account), 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 end
def after_authentication_url def after_authentication_url
@@ -83,10 +84,6 @@ module Authentication
cookies.signed.permanent[:session_token] = { value: session.signed_id, httponly: true, same_site: :lax } cookies.signed.permanent[:session_token] = { value: session.signed_id, httponly: true, same_site: :lax }
end end
def set_current_account
Current.account = Account.first
end
def terminate_session def terminate_session
Current.session.destroy Current.session.destroy
cookies.delete(:session_token) cookies.delete(:session_token)
@@ -7,7 +7,7 @@ class Sessions::LaunchpadController < ApplicationController
end end
def update 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? if user.present? && user.active?
start_new_session_for user start_new_session_for user
redirect_to after_authentication_url redirect_to after_authentication_url
-1
View File
@@ -1,7 +1,6 @@
class Current < ActiveSupport::CurrentAttributes class Current < ActiveSupport::CurrentAttributes
attribute :session attribute :session
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
attribute :account
delegate :user, to: :session, allow_nil: true delegate :user, to: :session, allow_nil: true
end end
+1 -1
View File
@@ -4,7 +4,7 @@
<nav class="header"> <nav class="header">
<div class="header__actions header__actions--start"></div> <div class="header__actions header__actions--start"></div>
<div class="header__actions header__actions--end"> <div class="header__actions header__actions--end">
<%= link_to Launchpad.login_url(account: Current.account), class: "btn", data: { controller: "hotkey", action: "keydown.esc@document->hotkey#click" } do %> <%= link_to Launchpad.login_url(account: Account.sole), class: "btn", data: { controller: "hotkey", action: "keydown.esc@document->hotkey#click" } do %>
<span class="for-screen-reader">Sign in instead</span> <span class="for-screen-reader">Sign in instead</span>
<% end %> <% end %>
</div> </div>
+1 -1
View File
@@ -34,7 +34,7 @@ def find_or_create_user(full_name, email_address)
) )
end end
signal_account = Account.first.signal_account signal_account = Account.sole.signal_account
signal_user = SignalId::User.find_or_create_by!(identity: signal_identity, account: signal_account) signal_user = SignalId::User.find_or_create_by!(identity: signal_identity, account: signal_account)
if user = User.find_by(signal_user_id: signal_user.id) if user = User.find_by(signal_user_id: signal_user.id)
+3 -3
View File
@@ -15,7 +15,7 @@ class BootstrapSignalId
puts "\n# tenant: #{tenant}" puts "\n# tenant: #{tenant}"
next unless check_account_preconditions next unless check_account_preconditions
create_signal_id_account if Account.first.queenbee_id.nil? create_signal_id_account if Account.sole.queenbee_id.nil?
create_signal_id_users create_signal_id_users
end end
@@ -42,7 +42,7 @@ class BootstrapSignalId
signal_id_account = SignalId::Account.find_by!(queenbee_id: queenbee_account.id) signal_id_account = SignalId::Account.find_by!(queenbee_id: queenbee_account.id)
signal_id_account.update_column :subdomain, ApplicationRecord.current_tenant signal_id_account.update_column :subdomain, ApplicationRecord.current_tenant
account = Account.first account = Account.sole
account.queenbee_id = queenbee_account.id account.queenbee_id = queenbee_account.id
account.name = ApplicationRecord.current_tenant account.name = ApplicationRecord.current_tenant
account.save! account.save!
@@ -50,7 +50,7 @@ class BootstrapSignalId
end end
def create_signal_id_users def create_signal_id_users
signal_account = Account.first.signal_account signal_account = Account.sole.signal_account
User.find_each do |user| User.find_each do |user|
if !user.system? && user.signal_user_id.nil? if !user.system? && user.signal_user_id.nil?
+1 -1
View File
@@ -4,7 +4,7 @@ COLLECTIONS_COUNT = 100
CARDS_PER_COLLECTION = 50 CARDS_PER_COLLECTION = 50
ApplicationRecord.current_tenant = "development-tenant" ApplicationRecord.current_tenant = "development-tenant"
account = Account.first account = Account.sole
user = account.users.first user = account.users.first
Current.session = user.sessions.last Current.session = user.sessions.last
workflow = account.workflows.first workflow = account.workflows.first
+1 -1
View File
@@ -3,7 +3,7 @@
require_relative "../config/environment" require_relative "../config/environment"
ApplicationRecord.with_each_tenant do |tenant| ApplicationRecord.with_each_tenant do |tenant|
account = Account.first account = Account.sole
signal_account = account.signal_account signal_account = account.signal_account
signal_users = SignalId::User.where(account_id: signal_account.id) signal_users = SignalId::User.where(account_id: signal_account.id)
+2 -2
View File
@@ -25,7 +25,7 @@ def fix_attachments(rich_text)
end end
ApplicationRecord.with_each_tenant do |tenant| ApplicationRecord.with_each_tenant do |tenant|
account_id = Account.first.queenbee_id account_id = Account.sole.queenbee_id
unless account_id unless account_id
puts "Skipping URL fixup for tenant: #{tenant}" puts "Skipping URL fixup for tenant: #{tenant}"
@@ -37,7 +37,7 @@ ApplicationRecord.with_each_tenant do |tenant|
domain = domains[Rails.env] || domains["production"] domain = domains[Rails.env] || domains["production"]
regex = %r{://\w+\.#{domain}/} regex = %r{://\w+\.#{domain}/}
pp [ Account.first.name, account_id, domain, regex ] pp [ Account.sole.name, account_id, domain, regex ]
puts puts
Card.find_each do |card| Card.find_each do |card|
+1 -1
View File
@@ -3,7 +3,7 @@ require_relative "../../config/environment"
CARDS_COUNT = 200 CARDS_COUNT = 200
ApplicationRecord.current_tenant = "37signals" ApplicationRecord.current_tenant = "37signals"
account = Account.first account = Account.sole
user = User.first user = User.first
Current.session = user.sessions.last Current.session = user.sessions.last
collection = Collection.first collection = Collection.first
+1 -1
View File
@@ -7,7 +7,7 @@ tenant_names = []
ApplicationRecord.with_each_tenant do |tenant| ApplicationRecord.with_each_tenant do |tenant|
next if tenant == "#{Rails.env}-tenant" next if tenant == "#{Rails.env}-tenant"
account = Account.first account = Account.sole
queenbee_id = account.queenbee_id queenbee_id = account.queenbee_id
tenant_names << { from: tenant, to: queenbee_id } tenant_names << { from: tenant, to: queenbee_id }