Class: Decidim::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::User
- Defined in:
- app/models/decidim/user.rb
Overview
A User is a citizen that wants to join the platform to participate.
Constant Summary collapse
- OMNIAUTH_PROVIDERS =
[:facebook, :twitter, :google_oauth2, (:developer if Rails.env.development?)].compact
- ROLES =
%w(admin user_manager).freeze
Instance Attribute Summary collapse
-
#invitation_instructions ⇒ Object
Public: Allows customizing the invitation instruction email content when inviting a user.
Class Method Summary collapse
-
.find_for_authentication(warden_conditions) ⇒ Object
Check if the user exists with the given email and the current organization.
Instance Method Summary collapse
-
#active_role ⇒ Object
Public: Returns the active role of the user.
-
#deleted? ⇒ Boolean
Check if the user account has been deleted or not.
- #follows?(followable) ⇒ Boolean
-
#name ⇒ Object
Public: returns the user’s name or the default one.
-
#role?(role) ⇒ Boolean
Checks if the user has the given ‘role` or not.
- #unread_conversations ⇒ Object
Instance Attribute Details
#invitation_instructions ⇒ Object
Public: Allows customizing the invitation instruction email content when inviting a user.
Returns a String.
42 43 44 |
# File 'app/models/decidim/user.rb', line 42 def invitation_instructions @invitation_instructions end |
Class Method Details
.find_for_authentication(warden_conditions) ⇒ Object
Check if the user exists with the given email and the current organization
warden_conditions - A hash with the authentication conditions
* email - a String that represents user's email.
* env - A Hash containing environment variables.
Returns a User.
83 84 85 86 87 88 89 |
# File 'app/models/decidim/user.rb', line 83 def self.find_for_authentication(warden_conditions) organization = warden_conditions.dig(:env, "decidim.current_organization") find_by( email: warden_conditions[:email], decidim_organization_id: organization.id ) end |
Instance Method Details
#active_role ⇒ Object
Public: Returns the active role of the user
55 56 57 |
# File 'app/models/decidim/user.rb', line 55 def active_role admin ? "admin" : roles.first end |
#deleted? ⇒ Boolean
Check if the user account has been deleted or not
65 66 67 |
# File 'app/models/decidim/user.rb', line 65 def deleted? deleted_at.present? end |
#follows?(followable) ⇒ Boolean
69 70 71 |
# File 'app/models/decidim/user.rb', line 69 def follows?(followable) Decidim::Follow.where(user: self, followable: followable).any? end |
#name ⇒ Object
Public: returns the user’s name or the default one
60 61 62 |
# File 'app/models/decidim/user.rb', line 60 def name super || I18n.t("decidim.anonymous_user") end |
#role?(role) ⇒ Boolean
Checks if the user has the given ‘role` or not.
role - a String or a Symbol that represents the role that is being
checked
Returns a boolean.
50 51 52 |
# File 'app/models/decidim/user.rb', line 50 def role?(role) roles.include?(role.to_s) end |
#unread_conversations ⇒ Object
73 74 75 |
# File 'app/models/decidim/user.rb', line 73 def unread_conversations Decidim::Messaging::Conversation.unread_by(self) end |