Class: Decidim::User

Inherits:
ApplicationRecord show all
Defined in:
decidim-core/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 user_manager).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.



38
39
40
# File 'decidim-core/app/models/decidim/user.rb', line 38

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 'decidim-core/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

#active_roleObject

Public: Returns the active role of the user



51
52
53
# File 'decidim-core/app/models/decidim/user.rb', line 51

def active_role
  admin ? "admin" : roles.first
end

#deleted?Boolean

Check if the user account has been deleted or not

Returns:

  • (Boolean)


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

def deleted?
  deleted_at.present?
end

#nameObject

Public: returns the user’s name or the default one



56
57
58
# File 'decidim-core/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)


46
47
48
# File 'decidim-core/app/models/decidim/user.rb', line 46

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