Class: Decidim::Admin::OfficializeUser

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

Overview

A command with all the business logic when officializing a user.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ OfficializeUser

Public: Initializes the command.

form - The officialization form.



10
11
12
# File 'decidim-admin/app/commands/decidim/admin/officialize_user.rb', line 10

def initialize(form)
  @form = form
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 the officialization suceeds.

  • :invalid when the form is invalid.

Returns nothing.



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

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

  officialize_user

  Decidim::EventsManager.publish(
    event: "decidim.events.users.user_officialized",
    event_class: Decidim::ProfileUpdatedEvent,
    resource: form.user,
    followers: form.user.followers
  )

  broadcast(:ok, form.user)
end