Files
fizzy/app/models/membership.rb
T
Stanko Krtalić 98755844a1 Remove the internal API
* Bind sessions to identities
* Remove references to the identity token
* Move email changes to identity
* Move account menu into a turbo-frame
* Create tenants from a tenanted route
2025-10-31 16:26:08 +01:00

31 lines
816 B
Ruby

class Membership < UntenantedRecord
belongs_to :identity, touch: true
serialize :context, coder: JSON
store_accessor :context, :join_code
class << self
def change_email_address(from:, to:, tenant:)
identity = Identity.find_by(email_address: from)
membership = find_by(tenant: tenant, identity: identity)
if membership
new_identity = Identity.find_or_create_by!(email_address: to)
membership.update!(identity: new_identity)
end
end
end
def account_name
ApplicationRecord.with_tenant(tenant) { Account.sole.name }
rescue ActiveRecord::Tenanted::TenantDoesNotExistError
nil
end
def user
ApplicationRecord.with_tenant(tenant) { User.find_by(membership_id: id) }
rescue ActiveRecord::Tenanted::TenantDoesNotExistError
nil
end
end