Class: Decidim::Plans::Admin::UpdatePlan

Inherits:
Rectify::Command
  • Object
show all
Includes:
Decidim::Plans::AttachmentMethods, NestedUpdater
Defined in:
app/commands/decidim/plans/admin/update_plan.rb

Overview

A command with all the business logic when a user updates a plan.

Instance Method Summary collapse

Constructor Details

#initialize(form, plan) ⇒ UpdatePlan

Public: Initializes the command.

form - A form object with the params. plan - the plan to update.



15
16
17
18
19
# File 'app/commands/decidim/plans/admin/update_plan.rb', line 15

def initialize(form, plan)
  @form = form
  @plan = plan
  @attached_to = plan
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the plan.

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

Returns nothing.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/commands/decidim/plans/admin/update_plan.rb', line 27

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

  if process_attachments?
    prepare_attachments
    return broadcast(:invalid) if attachments_invalid?
  end

  if form.invalid?
    mark_attachment_reattachment
    return broadcast(:invalid)
  end

  Decidim::Plans.tracer.trace!(form.current_user) do
    transaction do
      update_plan
      update_plan_contents
      update_plan_author
      update_attachments if process_attachments?
    end
  end

  broadcast(:ok, plan)
end