Class: Decidim::Verifications::AuthorizeUser
- Inherits:
-
Command
- Object
- Command
- Decidim::Verifications::AuthorizeUser
- Defined in:
- app/commands/decidim/verifications/authorize_user.rb
Overview
A command to authorize a user with an authorization handler.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(handler, organization) ⇒ AuthorizeUser
constructor
Public: Initializes the command.
Constructor Details
#initialize(handler, organization) ⇒ AuthorizeUser
Public: Initializes the command.
handler - An AuthorizationHandler object.
10 11 12 13 |
# File 'app/commands/decidim/verifications/authorize_user.rb', line 10 def initialize(handler, organization) @handler = handler @organization = organization end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the handler was not valid and we could not proceed.
-
:transferred if there is a duplicated authorization associated
to other user and the authorization can be transferred. -
:transfer_user if there is a duplicated authorization associated
to an ephemeral user and the current user is also ephemeral the session is transferred to the user with the existing
Returns nothing.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/commands/decidim/verifications/authorize_user.rb', line 28 def call if !handler.unique? && handler.user_transferrable? handler.user = handler.duplicate.user Authorization.create_or_update_from(handler) return broadcast(:transfer_user, handler.user) end return if !handler.unique? && handler.transferrable? if handler.invalid? register_conflict return broadcast(:invalid) end return broadcast(:invalid) unless set_tos_agreement Authorization.create_or_update_from(handler) broadcast(:ok) end |