Module: SubjModels::User
- Defined in:
- lib/subj_models/user.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
Constants included from TypesSupport::CardReceiveTypes
TypesSupport::CardReceiveTypes::CARD_RECEIVE_TYPES, TypesSupport::CardReceiveTypes::PICKUP, TypesSupport::CardReceiveTypes::POST_DELIVERY, TypesSupport::CardReceiveTypes::WITH_ORDER
Constants included from TypesSupport::UserTypes
TypesSupport::UserTypes::ADMIN, TypesSupport::UserTypes::LEGAL_PERSON, TypesSupport::UserTypes::NATURAL_PERSON, TypesSupport::UserTypes::USER_TYPES
Class Method Summary collapse
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #available_categories_ids ⇒ Object
- #available_nomenclature_ids ⇒ Object
- #legal_person? ⇒ Boolean
- #natural_person? ⇒ Boolean
- #password ⇒ Object
- #password=(password) ⇒ Object
- #to_s ⇒ Object
- #user_type=(value) ⇒ Object
- #valid_password?(password) ⇒ Boolean
Methods included from ValuesChecker
Class Method Details
.get_by_email(email) ⇒ Object
79 80 81 |
# File 'lib/subj_models/user.rb', line 79 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 |
# 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_many :user_delivery_addresses, dependent: :destroy # has_and_belongs_to_many :user_specializations # 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 :email, uniqueness: { case_sensitive: false }, presence: true, on: :update, unless: :skip_validations validates :phone, uniqueness: { case_sensitive: false }, presence: true, on: :update, unless: :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 end end |
Instance Method Details
#admin? ⇒ Boolean
99 100 101 |
# File 'lib/subj_models/user.rb', line 99 def admin? self.user_type == 'админ' end |
#available_categories_ids ⇒ Object
107 108 109 |
# File 'lib/subj_models/user.rb', line 107 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
103 104 105 |
# File 'lib/subj_models/user.rb', line 103 def available_nomenclature_ids Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id) end |
#legal_person? ⇒ Boolean
71 72 73 |
# File 'lib/subj_models/user.rb', line 71 def legal_person? user_type == USER_TYPES.key(LEGAL_PERSON) end |
#natural_person? ⇒ Boolean
67 68 69 |
# File 'lib/subj_models/user.rb', line 67 def natural_person? user_type == USER_TYPES.key(NATURAL_PERSON) end |
#password ⇒ Object
87 88 89 |
# File 'lib/subj_models/user.rb', line 87 def password self.encrypted_password end |
#password=(password) ⇒ Object
83 84 85 |
# File 'lib/subj_models/user.rb', line 83 def password=(password) self.encrypted_password = encrypt_password(password) unless password.blank? end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/subj_models/user.rb', line 95 def to_s email end |
#user_type=(value) ⇒ Object
75 76 77 |
# File 'lib/subj_models/user.rb', line 75 def user_type=(value) super(check_string_for_int(value)) end |
#valid_password?(password) ⇒ Boolean
91 92 93 |
# File 'lib/subj_models/user.rb', line 91 def valid_password?(password) self.encrypted_password == encrypt_password(password) end |