Class: Decidim::User

Inherits:
ApplicationRecord show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#invitation_instructionsObject

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

#abilityObject

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

Returns:

  • (Boolean)


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

def deleted?
  deleted_at.present?
end

#nameObject



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.

Returns:

  • (Boolean)


52
53
54
# File 'app/models/decidim/user.rb', line 52

def role?(role)
  roles.include?(role.to_s)
end