Class: Decidim::ActionDelegator::Participant

Inherits:
ApplicationRecord show all
Defined in:
app/models/decidim/action_delegator/participant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.phone_combinations(phones) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'app/models/decidim/action_delegator/participant.rb', line 56

def self.phone_combinations(phones)
  phones.map do |phone|
    phone_prefixes.map do |prefix|
      [
        "#{prefix}#{phone}",
        phone.delete_prefix(prefix)
      ]
    end
  end.flatten.uniq
end

.phone_prefixesObject



67
68
69
70
71
# File 'app/models/decidim/action_delegator/participant.rb', line 67

def self.phone_prefixes
  prefixes = [""]
  prefixes += ActionDelegator.phone_prefixes if ActionDelegator.phone_prefixes.respond_to?(:map)
  prefixes
end

.verifier_ids(seeds) ⇒ Object



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

def self.verifier_ids(seeds)
  seeds.map { |seed| Digest::MD5.hexdigest("#{seed}-#{Digest::MD5.hexdigest(Rails.application.secrets.secret_key_base)}") }
end

Instance Method Details

#last_loginObject



77
78
79
# File 'app/models/decidim/action_delegator/participant.rb', line 77

def 
  user&.
end

#ponderation_titleObject



81
82
83
# File 'app/models/decidim/action_delegator/participant.rb', line 81

def ponderation_title
  ponderation&.title
end

#uniq_idsObject



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

def uniq_ids
  @uniq_ids ||= Participant.verifier_ids(Participant.phone_combinations(["#{phone}-#{organization.id}"]))
end

#userObject



36
37
38
# File 'app/models/decidim/action_delegator/participant.rb', line 36

def user
  @user ||= decidim_user || 
end

#user_from_metadataObject



40
41
42
43
44
45
46
# File 'app/models/decidim/action_delegator/participant.rb', line 40

def 
  @user_from_metadata ||= if setting&.email_required?
                            Decidim::User.find_by(email: email, organization: setting.organization)
                          else
                            Decidim::Authorization.find_by(unique_id: uniq_ids)&.user
                          end
end

#user_nameObject



73
74
75
# File 'app/models/decidim/action_delegator/participant.rb', line 73

def user_name
  user&.name
end

#voted?Boolean

checks if the user has voted in the setting’s consultation

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
94
# File 'app/models/decidim/action_delegator/participant.rb', line 86

def voted?
  return false if user.blank?

  @voted ||= Decidim::Consultations::Vote
             .joins(question: :consultation)
             .where(decidim_consultations_questions: {
                      decidim_consultation_id: setting.consultation.id
                    }, author: user).any?
end