Module: SpreeCmCommissioner::UserDecorator
- Defined in:
- app/models/spree_cm_commissioner/user_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #display_name ⇒ Object
- #early_adopter? ⇒ Boolean
- #ensure_unique_database_delivery_method(attributes) ⇒ Object
- #full_name ⇒ Object
- #normal_user? ⇒ Boolean
- #organizer? ⇒ Boolean
- #push_notificable? ⇒ Boolean
- #soft_deleted? ⇒ Boolean
- #super_admin? ⇒ Boolean
- #update_otp_enabled ⇒ Object
- #validate_current_password!(password) ⇒ Object
Class Method Details
.define_user_places(base) ⇒ Object
53 54 55 56 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 53 def self.define_user_places(base) base.has_many :user_places, class_name: 'SpreeCmCommissioner::UserPlace' base.has_many :places, through: :user_places, class_name: 'SpreeCmCommissioner::Place' end |
.prepended(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 4 def self.prepended(base) base.include SpreeCmCommissioner::UserNotification base.include SpreeCmCommissioner::UserIdentity base.include SpreeCmCommissioner::UserPreference base.enum gender: %i[male female other] base.has_many :subscriptions, through: :customer, class_name: 'SpreeCmCommissioner::Subscription' base.has_many :payments, as: :payable, class_name: 'Spree::Payment', dependent: :nullify base.has_many :role_permissions, through: :spree_roles, class_name: 'SpreeCmCommissioner::RolePermission' base.has_many :permissions, through: :role_permissions, class_name: 'SpreeCmCommissioner::Permission' base.has_many :line_items, through: :orders, source: :line_items base.has_many :check_ins, foreign_key: 'check_in_by_id', class_name: 'SpreeCmCommissioner::CheckIn' base.has_many :user_events, class_name: 'SpreeCmCommissioner::UserEvent' base.has_many :events, through: :user_events, class_name: 'Spree::Taxon', source: 'taxon' base.has_many :guests, class_name: 'SpreeCmCommissioner::Guest', dependent: :destroy base.has_many :wished_items, class_name: 'Spree::WishedItem', through: :wishlists base.has_many :promotions, through: :promotion_rules, class_name: 'Spree::Promotion' base.has_one :profile, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::UserProfile' base.has_one :customer, class_name: 'SpreeCmCommissioner::Customer' base.has_secure_password :confirm_pin_code, validations: false base.multi_tenant :tenant, class_name: 'SpreeCmCommissioner::Tenant' base.scope :by_tenant, -> (tenant_id) { where(tenant_id: tenant_id) } base.whitelisted_ransackable_attributes = %w[email first_name last_name gender phone_number] base.before_save :update_otp_enabled define_user_places(base) def base.end_users joins('LEFT JOIN spree_vendor_users ON spree_users.id = spree_vendor_users.user_id').where(spree_vendor_users: { user_id: nil }) end def normal_user? system_user = admin? || !vendors.empty? normal_user = spree_roles.length == 1 ? spree_roles[0].name == 'user' : spree_roles.empty? normal_user && !system_user end def soft_deleted? !account_deletion_at.nil? end end |
Instance Method Details
#display_name ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 74 def display_name return full_name if full_name.present? return first_name if first_name.present? return last_name if last_name.present? return email if email.present? phone_number end |
#early_adopter? ⇒ Boolean
62 63 64 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 62 def early_adopter? has_spree_role?('early_adopter') end |
#ensure_unique_database_delivery_method(attributes) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 83 def ensure_unique_database_delivery_method(attributes) recipient = self = { recipient_id: recipient.id, notificable_id: attributes[:notificable].id, notificable_type: attributes[:notificable].class.to_s, type: attributes[:type] } notification = recipient.notifications.where().first_or_initialize if notification.persisted? notification.update(attributes) else notification.assign_attributes(attributes) notification.save! end notification end |
#full_name ⇒ Object
70 71 72 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 70 def full_name [first_name, last_name].compact_blank.join(' ') end |
#normal_user? ⇒ Boolean
42 43 44 45 46 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 42 def normal_user? system_user = admin? || !vendors.empty? normal_user = spree_roles.length == 1 ? spree_roles[0].name == 'user' : spree_roles.empty? normal_user && !system_user end |
#organizer? ⇒ Boolean
66 67 68 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 66 def organizer? has_spree_role?('organizer') end |
#push_notificable? ⇒ Boolean
105 106 107 108 109 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 105 def push_notificable? return false if device_tokens_count.blank? device_tokens_count.positive? end |
#soft_deleted? ⇒ Boolean
48 49 50 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 48 def soft_deleted? !account_deletion_at.nil? end |
#super_admin? ⇒ Boolean
58 59 60 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 58 def super_admin? has_spree_role?('super_admin') end |
#update_otp_enabled ⇒ Object
117 118 119 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 117 def update_otp_enabled self.otp_enabled = otp_email || otp_phone_number end |
#validate_current_password!(password) ⇒ Object
111 112 113 114 115 |
# File 'app/models/spree_cm_commissioner/user_decorator.rb', line 111 def validate_current_password!(password) return if valid_password?(password) errors.add(:password, I18n.t('spree_user.invalid_password')) end |