Class: Decidim::Verifications::AuthorizeUser

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

Overview

A command to authorize a user with an authorization handler.

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ AuthorizeUser

Public: Initializes the command.

handler - An AuthorizationHandler object.



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

def initialize(handler)
  @handler = handler
end

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.



20
21
22
23
24
25
26
# File 'app/commands/decidim/verifications/authorize_user.rb', line 20

def call
  return broadcast(:invalid) unless handler.valid?

  Authorization.create_or_update_from(handler)

  broadcast(:ok)
end