Module: SubjModels::UserModule
Defined Under Namespace
Modules: ClassMethods
Constant Summary
TypesSupport::CardReceiveTypes::CARD_RECEIVE_TYPES, TypesSupport::CardReceiveTypes::PICKUP, TypesSupport::CardReceiveTypes::POST_DELIVERY, TypesSupport::CardReceiveTypes::WITH_ORDER
TypesSupport::UserTypes::ADMIN, TypesSupport::UserTypes::DISTRIBUTOR, TypesSupport::UserTypes::LEGAL_PERSON, TypesSupport::UserTypes::NATURAL_PERSON, TypesSupport::UserTypes::USER_TYPES
Class Method Summary
collapse
Instance Method Summary
collapse
#check_string_for_int
Class Method Details
.get_by_email(email) ⇒ Object
88
89
90
|
# File 'lib/subj_models/user.rb', line 88
def self.get_by_email(email)
self.where(:email => email).first
end
|
.included(including_class) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/subj_models/user.rb', line 21
def self.included(including_class)
including_class.extend ClassMethods
including_class.class_eval do
include RademadeAdmin::UserModule
include SubjModels::ComprisingExternalId
include SubjModels::SharedScopes
enum user_type: USER_TYPES
enum card_receive_type: CARD_RECEIVE_TYPES
has_many :orders
has_many :user_specialization_approvals, dependent: :destroy
has_many :user_cards, dependent: :destroy
has_one :user_work_place, dependent: :destroy
has_one :user_card_delivery
has_many :user_delivery_addresses, dependent: :destroy
has_many :event_bookings, dependent: :destroy
has_and_belongs_to_many :user_specializations
has_and_belongs_to_many :brands
belongs_to :document_file
belongs_to :city
belongs_to :avatar, class_name: "DocumentFile"
validates :first_name, :last_name, presence: true,
on: :update,
unless: lambda { |user| user.legal_person? || user.skip_validations }
validates :user_type, inclusion: { in: user_types.keys },
on: :update,
unless: :skip_validations
attr_accessor :skip_validations
scope :external_id, -> external_id do
external_id ? where(external_id: external_id) : User.none
end
scope :internal_users, -> (condition) do
joins(:user_card_delivery).where.not(user_card_deliveries: {id: nil} ).where(external_id: nil)
end
end
end
|
Instance Method Details
#available_categories_ids ⇒ Object
112
113
114
|
# File 'lib/subj_models/user.rb', line 112
def available_categories_ids
Category.joins(:nomenclatures).where("nomenclatures.id IN (?) OR nomenclatures.is_professional=FALSE", available_nomenclature_ids).uniq.pluck(:id)
end
|
#available_nomenclature_ids ⇒ Object
108
109
110
|
# File 'lib/subj_models/user.rb', line 108
def available_nomenclature_ids
Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id)
end
|
#legal_person? ⇒ Boolean
80
81
82
|
# File 'lib/subj_models/user.rb', line 80
def legal_person?
user_type == USER_TYPES.key(LEGAL_PERSON)
end
|
#natural_person? ⇒ Boolean
#password ⇒ Object
96
97
98
|
# File 'lib/subj_models/user.rb', line 96
def password
self.encrypted_password
end
|
#password=(password) ⇒ Object
92
93
94
|
# File 'lib/subj_models/user.rb', line 92
def password=(password)
self.encrypted_password = encrypt_password(password) unless password.blank?
end
|
#to_s ⇒ Object
104
105
106
|
# File 'lib/subj_models/user.rb', line 104
def to_s
email
end
|
#user_type_value ⇒ Object
84
85
86
|
# File 'lib/subj_models/user.rb', line 84
def user_type_value
self[:user_type]
end
|
#valid_password?(password) ⇒ Boolean
100
101
102
|
# File 'lib/subj_models/user.rb', line 100
def valid_password?(password)
self.encrypted_password == encrypt_password(password)
end
|