Class: Decidim::Admin::ParticipatorySpace::UpdateAdmin

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

Instance Method Summary collapse

Constructor Details

#initialize(form, user_role, options = {}) ⇒ UpdateAdmin

Public: Initializes the command.

form - A form object with the params. user_role - The UserRole to update options: a hash with at least two mandatory keys, event_class and event

  • event_class - The event class to be used when notifying the user

  • event - The event name to be used when notifying the user



14
15
16
17
18
19
# File 'app/commands/decidim/admin/participatory_space/update_admin.rb', line 14

def initialize(form, user_role, options = {})
  @form = form
  @user_role = user_role
  @event_class = options.delete(:event_class)
  @event = options.delete(:event)
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



27
28
29
30
31
32
33
# File 'app/commands/decidim/admin/participatory_space/update_admin.rb', line 27

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

  update_role!
  broadcast(:ok)
end