Class: Integral::User

Inherits:
ApplicationRecord show all
Defined in:
app/models/integral/user.rb

Overview

User model used to represent a authenticated user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

available_statuses

Class Method Details

.available_localesArray

Returns containing available locales.

Returns:

  • (Array)

    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_iconObject



45
46
47
# File 'app/models/integral/user.rb', line 45

def self.integral_icon
  'user'
end

Instance Method Details

#active_for_authentication?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/integral/user.rb', line 94

def active_for_authentication?
  super && !blocked?
end

#avatar_filenameString

Return the avatar filename

Returns:

  • (String)

    return the avatar filename



61
62
63
# File 'app/models/integral/user.rb', line 61

def avatar_filename
  name
end

#inactive_messageObject



98
99
100
# File 'app/models/integral/user.rb', line 98

def inactive_message
  blocked? ? :blocked : super
end

#multiple_page_notifications?Boolean

Returns:

  • (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

Parameters:

  • subscribable (Class or Instance)

Returns:

  • (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

Parameters:

  • role_sym (Symbol)

    role(s) to check - Can be array of symbols or one symbol

Returns:

  • (Boolean)

    whether or not user has role(s)



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

Returns:

  • (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