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



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

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



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

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

.verifier_ids(seeds) ⇒ Object



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

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

Instance Method Details

#last_loginObject



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

def 
  user&.
end

#ponderation_titleObject



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

def ponderation_title
  ponderation&.title
end

#uniq_idsObject



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

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

#userObject



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

def user
  @user ||= decidim_user || 
end

#user_from_metadataObject



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

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



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

def user_name
  user&.name
end

#voted?Boolean

checks if the user has voted

Returns:

  • (Boolean)


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

def voted?
  return false if user.blank?

  # TODO: Replace vote check once new context is defined
  false
end