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



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

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



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

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

.verifier_ids(seeds) ⇒ Object



50
51
52
# File 'app/models/decidim/action_delegator/participant.rb', line 50

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



75
76
77
# File 'app/models/decidim/action_delegator/participant.rb', line 75

def 
  user&.
end

#ponderation_titleObject



79
80
81
# File 'app/models/decidim/action_delegator/participant.rb', line 79

def ponderation_title
  ponderation&.title
end

#uniq_idsObject



46
47
48
# File 'app/models/decidim/action_delegator/participant.rb', line 46

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

#userObject



34
35
36
# File 'app/models/decidim/action_delegator/participant.rb', line 34

def user
  @user ||= decidim_user || 
end

#user_from_metadataObject



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

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



71
72
73
# File 'app/models/decidim/action_delegator/participant.rb', line 71

def user_name
  user&.name
end

#voted?Boolean

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

Returns:

  • (Boolean)


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

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