Class: Decidim::Kids::AuthorizeMinor

Inherits:
Command
  • Object
show all
Includes:
AgeMethods
Defined in:
app/commands/decidim/kids/authorize_minor.rb

Overview

A command to authorize a user with an authorization handler.

Instance Method Summary collapse

Methods included from AgeMethods

#age_from_birthday, #age_from_date

Constructor Details

#initialize(handler) ⇒ AuthorizeMinor

Public: Initializes the command.

handler - An AuthorizationHandler object.



12
13
14
# File 'app/commands/decidim/kids/authorize_minor.rb', line 12

def initialize(handler)
  @handler = handler
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/commands/decidim/kids/authorize_minor.rb', line 16

def call
  return broadcast(:invalid) unless handler.user.minor?
  return broadcast(:invalid_age) unless valid_age?

  result = :ok
  Decidim::Verifications::AuthorizeUser.call(handler, handler.user.organization) do
    on(:ok) do
      handler.user.blocked = false
      handler.user.blocked_at = nil
      handler.user.name = handler.user.minor_data.name

      handler.user.invite!(handler.user, invitation_instructions: "invite_minor")
    end
    on(:invalid) { result = :invalid }
    on(:transferred) { result = :transferred }
  end
  broadcast(result)
end