Sha256: a42c0212ebba6e3ec91cebfe2816f497aefa757bad5394f06a822ef688c762db
Contents?: true
Size: 1.65 KB
Versions: 7
Compression:
Stored size: 1.65 KB
Contents
# frozen_string_literal: true module Decidim module Elections module Admin # This command is executed when the user updates an Answer # from the admin panel. class UpdateAnswer < Decidim::Command include ::Decidim::GalleryMethods def initialize(form, answer) @form = form @answer = answer @attached_to = answer end # Updates the answer if valid. # # Broadcasts :ok if successful, :invalid otherwise. def call return broadcast(:invalid) if invalid? if process_gallery? build_gallery return broadcast(:invalid) if gallery_invalid? end transaction do update_answer link_proposals create_gallery if process_gallery? photo_cleanup! end broadcast(:ok, answer) end private attr_reader :form, :answer, :gallery def invalid? form.election.blocked? || form.invalid? end def update_answer attributes = { question: form.question, title: form.title, description: form.description, weight: form.weight } Decidim.traceability.update!( answer, form.current_user, attributes, visibility: "all" ) end def proposals @proposals ||= answer.sibling_scope(:proposals).where(id: form.proposal_ids) end def link_proposals answer.link_resources(proposals, "related_proposals") end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems