Sha256: 889fb90ea097a37719989b1f8313b65db388312bdf8723ac36f6939d6cb62d8f
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
# frozen_string_literal: true module Decidim module Templates module Admin class UpdateProposalAnswerTemplate < Rectify::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: { internal_state: @form.internal_state }, target: :proposal_answer ) resource = identify_templateable_resource @template.update!(templatable: resource) broadcast(:ok, @template) end private def identify_templateable_resource resource = @form.scope_for_availability.split("-") case resource.first when "organizations" @form.current_organization when "components" component = Decidim::Component.find_by(id: resource.last) component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? component : nil end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-reporting_proposals-0.4.2 | app/commands/decidim/templates/admin/update_proposal_answer_template.rb |