Class: Decidim::Templates::Admin::UpdateTemplate

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/templates/admin/update_template.rb

Overview

Updates the questionnaire template given form data.

Instance Method Summary collapse

Constructor Details

#initialize(template, form, user) ⇒ UpdateTemplate

Initializes the command.

template - The Template to update. form - The form object containing the data to update. user - The user that updates the template.



13
14
15
16
17
# File 'app/commands/decidim/templates/admin/update_template.rb', line 13

def initialize(template, form, user)
  @template = template
  @form = form
  @user = user
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/commands/decidim/templates/admin/update_template.rb', line 19

def call
  return broadcast(:invalid) unless @form.valid?
  return broadcast(:invalid) unless @user.organization == @template.organization

  @template = Decidim.traceability.update!(
    @template,
    @user,
    name: @form.name,
    description: @form.description
  )

  broadcast(:ok, @template)
end