Class: Decidim::AuthorizeUser

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/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.



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

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.



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

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

  create_authorization
  broadcast(:ok)
end