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
- MAXIMUM_AVATAR_FILE_SIZE =
5.megabytes
- ROLES =
%w(admin moderator collaborator official).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
-
#ability ⇒ Object
Gets the ability instance for the given user.
-
#deleted? ⇒ Boolean
Check if the user account has been deleted or not.
- #name ⇒ Object
-
#role?(role) ⇒ Boolean
Checks if the user has the given ‘role` or not.
Instance Attribute Details
#invitation_instructions ⇒ Object
Public: Allows customizing the invitation instruction email content when inviting a user.
Returns a String.
37 38 39 |
# File 'app/models/decidim/user.rb', line 37 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.
71 72 73 74 75 76 77 |
# File 'app/models/decidim/user.rb', line 71 def self.find_for_authentication(warden_conditions) organization = warden_conditions.dig(:env, "decidim.current_organization") where( email: warden_conditions[:email], decidim_organization_id: organization.id ).first end |
Instance Method Details
#ability ⇒ Object
Gets the ability instance for the given user.
42 43 44 |
# File 'app/models/decidim/user.rb', line 42 def ability @ability ||= Ability.new(self) end |
#deleted? ⇒ Boolean
Check if the user account has been deleted or not
61 62 63 |
# File 'app/models/decidim/user.rb', line 61 def deleted? deleted_at.present? end |
#name ⇒ Object
56 57 58 |
# File 'app/models/decidim/user.rb', line 56 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.
52 53 54 |
# File 'app/models/decidim/user.rb', line 52 def role?(role) roles.include?(role.to_s) end |