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.
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_prefixes ⇒ Object
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_login ⇒ Object
76 77 78 |
# File 'app/models/decidim/action_delegator/participant.rb', line 76 def last_login user&.last_sign_in_at end |
#ponderation_title ⇒ Object
80 81 82 |
# File 'app/models/decidim/action_delegator/participant.rb', line 80 def ponderation_title ponderation&.title end |
#uniq_ids ⇒ Object
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 |
#user ⇒ Object
35 36 37 |
# File 'app/models/decidim/action_delegator/participant.rb', line 35 def user @user ||= decidim_user || end |
#user_from_metadata ⇒ Object
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_name ⇒ Object
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
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 |