Sha256: d0c7e1a9bd85ff37cb0621fa2e6817443d52b590da5f6b55beb0df33818463ff
Contents?: true
Size: 1.47 KB
Versions: 6
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module Decidim module Templates module Admin class UpdateProposalAnswerTemplate < Decidim::Command # Initializes the command. # # template - The Template to update. # form - The form object containing the data to update. # user - The user that updates the template. def initialize(template, form, user) @template = template @form = form @user = user end 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 private def identify_templateable_resource found_component = Decidim::Component.find_by(id: @form.component_constraint, manifest_name: "proposals") if found_component.present? resource = found_component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? found_component : nil end resource end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems