Class: Decidim::User
- Inherits:
-
UserBaseEntity
- Object
- ActiveRecord::Base
- ApplicationRecord
- UserBaseEntity
- Decidim::User
- Includes:
- ActsAsAuthor, DataPortability, Searchable
- Defined in:
- app/models/decidim/user.rb
Overview
A User is a citizen that wants to join the platform to participate.
Defined Under Namespace
Classes: Roles
Constant Summary collapse
- OMNIAUTH_PROVIDERS =
[:facebook, :twitter, :google_oauth2, (:developer if Rails.env.development?)].compact
Instance Attribute Summary collapse
-
#invitation_instructions ⇒ Object
Public: Allows customizing the invitation instruction email content when inviting a user.
-
#newsletter_notifications ⇒ Object
Returns the value of attribute newsletter_notifications.
Class Method Summary collapse
- .data_portability_images(user) ⇒ Object
- .export_serializer ⇒ Object
-
.find_for_authentication(warden_conditions) ⇒ Object
Check if the user exists with the given email and the current organization.
- .log_presenter_class_for(_log) ⇒ Object
- .user_collection(user) ⇒ Object
Instance Method Summary collapse
-
#active_role ⇒ Object
Public: Returns the active role of the user.
- #being_impersonated? ⇒ Boolean
-
#deleted? ⇒ Boolean
Check if the user account has been deleted or not.
- #follows?(followable) ⇒ Boolean
- #interested_scopes ⇒ Object
- #interested_scopes_ids ⇒ Object
-
#name ⇒ Object
Public: returns the user’s name or the default one.
-
#officialized? ⇒ Boolean
Public: whether the user has been officialized or not.
-
#presenter ⇒ Object
Returns the presenter for this author, to be used in the views.
-
#role?(role) ⇒ Boolean
Checks if the user has the given ‘role` or not.
- #tos_accepted? ⇒ Boolean
- #unread_conversations ⇒ Object
- #user_invited? ⇒ Boolean
-
#verifiable? ⇒ Boolean
Whether this user can be verified against some authorization or not.
Methods included from Searchable
searchable_resources, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space
Methods inherited from UserBaseEntity
Methods included from Followable
Instance Attribute Details
#invitation_instructions ⇒ Object
Public: Allows customizing the invitation instruction email content when inviting a user.
Returns a String.
83 84 85 |
# File 'app/models/decidim/user.rb', line 83 def invitation_instructions @invitation_instructions end |
#newsletter_notifications ⇒ Object
Returns the value of attribute newsletter_notifications.
62 63 64 |
# File 'app/models/decidim/user.rb', line 62 def @newsletter_notifications end |
Class Method Details
.data_portability_images(user) ⇒ Object
155 156 157 |
# File 'app/models/decidim/user.rb', line 155 def self.data_portability_images(user) user_collection(user).map(&:avatar) end |
.export_serializer ⇒ Object
151 152 153 |
# File 'app/models/decidim/user.rb', line 151 def self.export_serializer Decidim::DataPortabilitySerializers::DataPortabilityUserSerializer end |
.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.
139 140 141 142 143 144 145 |
# File 'app/models/decidim/user.rb', line 139 def self.find_for_authentication(warden_conditions) organization = warden_conditions.dig(:env, "decidim.current_organization") find_by( email: warden_conditions[:email].to_s.downcase, decidim_organization_id: organization.id ) end |
.log_presenter_class_for(_log) ⇒ Object
91 92 93 |
# File 'app/models/decidim/user.rb', line 91 def self.log_presenter_class_for(_log) Decidim::AdminLog::UserPresenter end |
.user_collection(user) ⇒ Object
147 148 149 |
# File 'app/models/decidim/user.rb', line 147 def self.user_collection(user) where(id: user.id) end |
Instance Method Details
#active_role ⇒ Object
Public: Returns the active role of the user
106 107 108 |
# File 'app/models/decidim/user.rb', line 106 def active_role admin ? "admin" : roles.first end |
#being_impersonated? ⇒ Boolean
174 175 176 |
# File 'app/models/decidim/user.rb', line 174 def being_impersonated? ImpersonationLog.active.where(user: self).exists? end |
#deleted? ⇒ Boolean
Check if the user account has been deleted or not
116 117 118 |
# File 'app/models/decidim/user.rb', line 116 def deleted? deleted_at.present? end |
#follows?(followable) ⇒ Boolean
125 126 127 |
# File 'app/models/decidim/user.rb', line 125 def follows?(followable) Decidim::Follow.where(user: self, followable: followable).any? end |
#interested_scopes ⇒ Object
182 183 184 |
# File 'app/models/decidim/user.rb', line 182 def interested_scopes @interested_scopes ||= organization.scopes.where(id: interested_scopes_ids) end |
#interested_scopes_ids ⇒ Object
178 179 180 |
# File 'app/models/decidim/user.rb', line 178 def interested_scopes_ids extended_data["interested_scopes"] || [] end |
#name ⇒ Object
Public: returns the user’s name or the default one
111 112 113 |
# File 'app/models/decidim/user.rb', line 111 def name super || I18n.t("decidim.anonymous_user") end |
#officialized? ⇒ Boolean
Public: whether the user has been officialized or not
121 122 123 |
# File 'app/models/decidim/user.rb', line 121 def officialized? !officialized_at.nil? end |
#presenter ⇒ Object
Returns the presenter for this author, to be used in the views. Required by ActsAsAuthor.
87 88 89 |
# File 'app/models/decidim/user.rb', line 87 def presenter Decidim::UserPresenter.new(self) 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.
101 102 103 |
# File 'app/models/decidim/user.rb', line 101 def role?(role) roles.include?(role.to_s) end |
#tos_accepted? ⇒ Boolean
159 160 161 162 163 164 165 166 167 |
# File 'app/models/decidim/user.rb', line 159 def tos_accepted? return true if managed return false if accepted_tos_version.nil? # For some reason, if we don't use `#to_i` here we get some # cases where the comparison returns false, but calling `#to_i` returns # the same number :/ accepted_tos_version.to_i >= organization.tos_version.to_i end |
#unread_conversations ⇒ Object
129 130 131 |
# File 'app/models/decidim/user.rb', line 129 def unread_conversations Decidim::Messaging::Conversation.unread_by(self) end |
#user_invited? ⇒ Boolean
75 76 77 |
# File 'app/models/decidim/user.rb', line 75 def user_invited? invitation_token_changed? && invitation_accepted_at_changed? end |
#verifiable? ⇒ Boolean
Whether this user can be verified against some authorization or not.
170 171 172 |
# File 'app/models/decidim/user.rb', line 170 def verifiable? confirmed? || managed? || being_impersonated? end |