Class: Decidim::Verifications::AuthorizeUser

Inherits:
Command
  • Object
show all
Defined in:
decidim-verifications/app/commands/decidim/verifications/authorize_user.rb

Overview

A command to authorize a user with an authorization handler.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(handler, organization) ⇒ AuthorizeUser

Public: Initializes the command.

handler - An AuthorizationHandler object.



10
11
12
13
# File 'decidim-verifications/app/commands/decidim/verifications/authorize_user.rb', line 10

def initialize(handler, organization)
  @handler = handler
  @organization = organization
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the handler was not valid and we could not proceed.

Returns nothing.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-verifications/app/commands/decidim/verifications/authorize_user.rb', line 21

def call
  return transfer_authorization if !handler.unique? && handler.transferrable?

  if handler.invalid?
    register_conflict

    return broadcast(:invalid)
  end

  Authorization.create_or_update_from(handler)

  broadcast(:ok)
end