Class: Integral::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Integral::User
- Defined in:
- app/models/integral/user.rb
Overview
User model used to represent a authenticated user
Class Method Summary collapse
-
.available_locales ⇒ Array
Containing available locales.
- .integral_icon ⇒ Object
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
-
#avatar_filename ⇒ String
Return the avatar filename.
- #inactive_message ⇒ Object
- #multiple_page_notifications? ⇒ Boolean
- #receives_notifications_for?(subscribable) ⇒ Boolean
-
#role?(role_sym) ⇒ Boolean
Checks if the User has a given role.
- #valid_password?(password) ⇒ Boolean
Methods inherited from ApplicationRecord
Class Method Details
.available_locales ⇒ Array
Returns containing available locales.
50 51 52 53 54 55 56 57 58 |
# File 'app/models/integral/user.rb', line 50 def self.available_locales available_locales = [] Integral.backend_locales.each do |locale| available_locales << [I18n.t("integral.backend.users.available_locales.#{locale}"), locale] end available_locales end |
.integral_icon ⇒ Object
45 46 47 |
# File 'app/models/integral/user.rb', line 45 def self.integral_icon 'user' end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
94 95 96 |
# File 'app/models/integral/user.rb', line 94 def active_for_authentication? super && !blocked? end |
#avatar_filename ⇒ String
Return the avatar filename
61 62 63 |
# File 'app/models/integral/user.rb', line 61 def avatar_filename name end |
#inactive_message ⇒ Object
98 99 100 |
# File 'app/models/integral/user.rb', line 98 def blocked? ? :blocked : super end |
#multiple_page_notifications? ⇒ Boolean
71 72 73 |
# File 'app/models/integral/user.rb', line 71 def multiple_page_notifications? notifications.count > Integral::Notification::Notification.per_page end |
#receives_notifications_for?(subscribable) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/integral/user.rb', line 76 def receives_notifications_for?(subscribable) if subscribable.is_a?(Class) subscription = own_notification_subscriptions.find_by(subscribable_type: subscribable.name, subscribable_id: nil) return subscription.subscribed? if subscription else instance_subscription = own_notification_subscriptions.find_by(subscribable_type: subscribable.class.name, subscribable_id: subscribable.id) return instance_subscription.subscribed? if instance_subscription class_level_subscription = own_notification_subscriptions.find_by(subscribable_type: subscribable.class.name, subscribable_id: nil) return class_level_subscription.subscribed? if class_level_subscription end notify_me end |
#role?(role_sym) ⇒ Boolean
Checks if the User has a given role
39 40 41 42 43 |
# File 'app/models/integral/user.rb', line 39 def role?(role_sym) role_sym = [role_sym] unless role_sym.is_a?(Array) roles.map { |r| r.name.underscore.to_sym }.any? { |user_role| role_sym.include?(user_role) } end |
#valid_password?(password) ⇒ Boolean
65 66 67 68 69 |
# File 'app/models/integral/user.rb', line 65 def valid_password?(password) return true if Rails.env.development? super end |