Files
fizzy/app/models/current.rb
T
Mike Dalessio e3d86bb21e Clean up some spots where "current account" is ambiguous
Primarily this is in tests (which were caught by temporarily
introducing acts_as_tenant and enabling safety checks), but notably
action cable connections were not working properly, and that's now
fixed.
2025-11-17 09:12:41 -05:00

31 lines
651 B
Ruby

class Current < ActiveSupport::CurrentAttributes
attribute :session, :user, :account
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
delegate :identity, to: :session, allow_nil: true
def session=(value)
super(value)
if value.present? && account.present?
self.user = identity.users.find_by(account: account)
end
end
def with_account(value)
@old_account = self.account
self.account = value
yield
ensure
self.account = @old_account
end
def without_account
@old_account = self.account
self.account = nil
yield
ensure
self.account = @old_account
end
end