Class: Decidim::DirectVerifications::UserProcessor
- Inherits:
-
Object
- Object
- Decidim::DirectVerifications::UserProcessor
- Defined in:
- lib/decidim/direct_verifications/user_processor.rb
Instance Attribute Summary collapse
-
#authorization_handler ⇒ Object
Returns the value of attribute authorization_handler.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
Instance Method Summary collapse
- #authorize_users ⇒ Object
-
#initialize(organization, current_user) ⇒ UserProcessor
constructor
A new instance of UserProcessor.
- #register_users ⇒ Object
- #revoke_users ⇒ Object
- #total(type) ⇒ Object
Constructor Details
#initialize(organization, current_user) ⇒ UserProcessor
Returns a new instance of UserProcessor.
6 7 8 9 10 11 12 13 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 6 def initialize(organization, current_user) @organization = organization @current_user = current_user = :direct_verifications @errors = { registered: [], authorized: [], revoked: [] } @processed = { registered: [], authorized: [], revoked: [] } @emails = {} end |
Instance Attribute Details
#authorization_handler ⇒ Object
Returns the value of attribute authorization_handler.
16 17 18 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 16 def end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
15 16 17 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 15 def current_user @current_user end |
#emails ⇒ Object
Returns the value of attribute emails.
15 16 17 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 15 def emails @emails end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 15 def errors @errors end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
15 16 17 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 15 def organization @organization end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
15 16 17 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 15 def processed @processed end |
Instance Method Details
#authorize_users ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 42 def @emails.each do |email, _name| if (u = find_user(email)) auth = (u) next if auth.granted? Verification::ConfirmUserAuthorization.call(auth, (u)) do on(:ok) do add_processed :authorized, email end on(:invalid) do add_error :authorized, email end end else add_error :authorized, email end end end |
#register_users ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 22 def register_users @emails.each do |email, name| next if find_user(email) form = register_form(email, name) begin InviteUser.call(form) do on(:ok) do add_processed :registered, email log_action find_user(email) end on(:invalid) do add_error :registered, email end end rescue StandardError add_error :registered, email end end end |
#revoke_users ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 61 def revoke_users @emails.each do |email, _name| if (u = find_user(email)) auth = (u) next unless auth.granted? Verification::DestroyUserAuthorization.call(auth) do on(:ok) do add_processed :revoked, email end on(:invalid) do add_error :revoked, email end end else add_error :revoked, email end end end |
#total(type) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/decidim/direct_verifications/user_processor.rb', line 80 def total(type) if type == :registered return User.where(email: @emails.keys, decidim_organization_id: @organization.id) .count end if type == :unconfirmed return User.where(email: @emails.keys, decidim_organization_id: @organization.id) .where(confirmed_at: nil).count end if type == :authorized return Decidim::Authorization.joins(:user) .where(name: ) .where("decidim_users.email IN (:emails) AND decidim_users.decidim_organization_id=:org", emails: @emails.keys, org: @organization.id).count end 0 end |