Sha256: fe3eb441c55d1077e7e50ffd8faa0275bad31577cf6e306c93ccf8d015ae01c3
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
# frozen_string_literal: true module Decidim module Templates module Admin class CreateProposalAnswerTemplate < Rectify::Command # Initializes the command. # # form - The source for this ProposalAnswerTemplate. def initialize(form) @form = form end def call return broadcast(:invalid) unless @form.valid? @template = Decidim.traceability.create!( Template, @form.current_user, name: @form.name, description: @form.description, organization: @form.current_organization, 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/create_proposal_answer_template.rb |