Class: Decidim::ActionDelegator::Admin::CreateDelegation

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

Instance Method Summary collapse

Constructor Details

#initialize(form, performed_by, current_setting) ⇒ CreateDelegation

Public: Initializes the command.

form - A form object with the params. delegated_by - The user performing the operation



11
12
13
14
15
# File 'app/commands/decidim/action_delegator/admin/create_delegation.rb', line 11

def initialize(form, performed_by, current_setting)
  @form = form
  @performed_by = performed_by
  @current_setting = current_setting
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form wasn’t valid and we couldn’t proceed.

Returns nothing.



23
24
25
26
27
28
29
30
31
32
# File 'app/commands/decidim/action_delegator/admin/create_delegation.rb', line 23

def call
  return broadcast(:error, generic_error_message) if form.invalid? || current_setting.nil?
  return broadcast(:error, above_max_grants_error_message) if above_max_grants?

  create_delegation

  return broadcast(:ok) if delegation.persisted?

  broadcast(:error, delegation.errors.full_messages.first)
end