Class: Decidim::Templates::Admin::UpdateProposalAnswerTemplate

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

Instance Method Summary collapse

Constructor Details

#initialize(template, form, user) ⇒ UpdateProposalAnswerTemplate

Initializes the command.

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



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

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

Instance Method Details

#callObject



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

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,
    field_values: { proposal_state_id: @form.proposal_state_id },
    target: :proposal_answer
  )

  @template.update!(templatable: identify_templateable_resource)

  broadcast(:ok, @template)
end