1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/account.rb

37 lines
833 B
Ruby
Raw Normal View History

2018-12-01 21:03:19 -05:00
# frozen_string_literal: true
class Account < ApplicationRecord
2018-12-05 20:22:39 -05:00
rolify role_join_table_name: :account_roles
2018-12-01 21:28:34 -05:00
2018-12-09 22:36:09 -05:00
belongs_to :person, optional: true
2018-12-01 21:50:10 -05:00
has_one :user, dependent: :restrict_with_exception
2018-12-11 19:15:40 -05:00
has_many :account_telegram_contacts,
dependent: :restrict_with_exception
has_many :own_membership_apps,
class_name: 'MembershipApp',
dependent: :restrict_with_exception
2018-12-01 21:28:34 -05:00
has_many :passport_confirmations, dependent: :restrict_with_exception
2018-12-04 20:49:26 -05:00
scope :guests, -> { includes(:user).where(users: { id: nil }) }
2018-12-09 21:52:34 -05:00
before_create do
self.guest_token = SecureRandom.hex
end
2018-12-09 22:36:09 -05:00
validates :person_id, allow_nil: true, uniqueness: true
2018-12-04 20:49:26 -05:00
def guest?
user.nil?
end
def add_role(_role_name, _resource = nil)
raise 'can not add role to guest account' if guest?
super
end
2018-12-01 21:03:19 -05:00
end