Class: Decidim::ActionDelegator::Participant
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::ActionDelegator::Participant
- Defined in:
- app/models/decidim/action_delegator/participant.rb
Class Method Summary collapse
Instance Method Summary collapse
- #last_login ⇒ Object
- #ponderation_title ⇒ Object
- #uniq_ids ⇒ Object
- #user ⇒ Object
- #user_from_metadata ⇒ Object
- #user_name ⇒ Object
-
#voted? ⇒ Boolean
checks if the user has voted in the setting’s consultation.
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_prefixes ⇒ Object
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_login ⇒ Object
77 78 79 |
# File 'app/models/decidim/action_delegator/participant.rb', line 77 def last_login user&.last_sign_in_at end |
#ponderation_title ⇒ Object
81 82 83 |
# File 'app/models/decidim/action_delegator/participant.rb', line 81 def ponderation_title ponderation&.title end |
#uniq_ids ⇒ Object
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 |
#user ⇒ Object
36 37 38 |
# File 'app/models/decidim/action_delegator/participant.rb', line 36 def user @user ||= decidim_user || end |
#user_from_metadata ⇒ Object
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_name ⇒ Object
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
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 |