2018-12-02 02:03:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Account < ApplicationRecord
|
2018-12-06 01:22:39 +00:00
|
|
|
rolify role_join_table_name: :account_roles
|
2018-12-02 02:28:34 +00:00
|
|
|
|
2018-12-02 02:50:10 +00:00
|
|
|
has_one :user, dependent: :restrict_with_exception
|
|
|
|
|
2018-12-06 22:39:11 +00:00
|
|
|
has_many :own_membership_apps,
|
|
|
|
class_name: 'MembershipApp',
|
|
|
|
dependent: :restrict_with_exception
|
2018-12-02 10:54:56 +00:00
|
|
|
|
2018-12-02 02:28:34 +00:00
|
|
|
has_many :passport_confirmations, dependent: :restrict_with_exception
|
2018-12-05 01:49:26 +00:00
|
|
|
|
|
|
|
scope :guests, -> { includes(:user).where(users: { id: nil }) }
|
|
|
|
|
2018-12-10 02:52:34 +00:00
|
|
|
before_create do
|
|
|
|
self.guest_token = SecureRandom.hex
|
|
|
|
end
|
|
|
|
|
2018-12-05 01:49:26 +00:00
|
|
|
def guest?
|
|
|
|
user.nil?
|
|
|
|
end
|
2018-12-06 01:55:35 +00:00
|
|
|
|
|
|
|
def add_role(_role_name, _resource = nil)
|
|
|
|
raise 'can not add role to guest account' if guest?
|
2018-12-06 01:56:52 +00:00
|
|
|
|
2018-12-06 01:55:35 +00:00
|
|
|
super
|
|
|
|
end
|
2018-12-02 02:03:19 +00:00
|
|
|
end
|