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

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 wasn't valid and we couldn't proceed.

Returns nothing.


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

def call
  if handler.invalid?
    conflict = create_verification_conflict
    notify_admins(conflict) if conflict.present?

    return broadcast(:invalid)
  end

  Authorization.create_or_update_from(handler)

  broadcast(:ok)
end