Module: SubjModels::UserModule
- 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::DISTRIBUTOR, TypesSupport::UserTypes::LEGAL_PERSON, TypesSupport::UserTypes::NATURAL_PERSON, TypesSupport::UserTypes::USER_TYPES
Class Method Summary collapse
Instance Method Summary collapse
- #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
94 95 96 |
# File 'lib/subj_models/user.rb', line 94 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 75 76 77 78 79 80 |
# 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 :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 scope :internal_users, -> (condition) do joins(:user_card_delivery).where.not(user_card_deliveries: {id: nil} ).where(external_id: nil) end scope :updated_at_last_day, -> (date) do where.not(external_id: nil) .joins(:user_specialization_approvals) .where("user_specialization_approvals.updated_at > ? OR users.updated_at > ?", date.to_datetime, date.to_datetime) end end end |
Instance Method Details
#available_categories_ids ⇒ Object
118 119 120 |
# File 'lib/subj_models/user.rb', line 118 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
114 115 116 |
# File 'lib/subj_models/user.rb', line 114 def available_nomenclature_ids Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id) end |
#legal_person? ⇒ Boolean
86 87 88 |
# File 'lib/subj_models/user.rb', line 86 def legal_person? user_type == USER_TYPES.key(LEGAL_PERSON) end |
#natural_person? ⇒ Boolean
82 83 84 |
# File 'lib/subj_models/user.rb', line 82 def natural_person? user_type == USER_TYPES.key(NATURAL_PERSON) end |
#password ⇒ Object
102 103 104 |
# File 'lib/subj_models/user.rb', line 102 def password self.encrypted_password end |
#password=(password) ⇒ Object
98 99 100 |
# File 'lib/subj_models/user.rb', line 98 def password=(password) self.encrypted_password = encrypt_password(password) unless password.blank? end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/subj_models/user.rb', line 110 def to_s email end |
#user_type_value ⇒ Object
90 91 92 |
# File 'lib/subj_models/user.rb', line 90 def user_type_value self[:user_type] end |
#valid_password?(password) ⇒ Boolean
106 107 108 |
# File 'lib/subj_models/user.rb', line 106 def valid_password?(password) self.encrypted_password == encrypt_password(password) end |