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

OMNIAUTH_PROVIDERS =
[:facebook, :twitter, :google_oauth2, (:developer if Rails.env.development?)].compact
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.



40
41
42
# File 'app/models/decidim/user.rb', line 40

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.



77
78
79
80
81
82
83
# File 'app/models/decidim/user.rb', line 77

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



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

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

#deleted?Boolean

Check if the user account has been deleted or not

Returns:

  • (Boolean)


63
64
65
# File 'app/models/decidim/user.rb', line 63

def deleted?
  deleted_at.present?
end

#follows?(followable) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/decidim/user.rb', line 67

def follows?(followable)
  Decidim::Follow.where(user: self, followable: followable).any?
end

#nameObject

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



58
59
60
# File 'app/models/decidim/user.rb', line 58

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)


48
49
50
# File 'app/models/decidim/user.rb', line 48

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