Sha256: c957c2cd8878d93716c94a2fa87ef55e1d04d16d9d084d26ad73a2cd97fb02fe
Contents?: true
Size: 1.47 KB
Versions: 19
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module Decidim module Meetings module Admin # This command is executed when the user changes a Questionnaire from the admin # panel. class UpdateQuestionStatus < Rectify::Command class InvalidStatus < StandardError; end # Initializes a UpdateQuestionnaire Command. # # form - The form from which to get the data. # questionnaire - The current instance of the questionnaire to be updated. def initialize(question, current_user) @question = question @current_user = current_user end # Updates the questionnaire if valid. # # Broadcasts :ok if successful, :invalid otherwise. def call Decidim::Meetings::Question.transaction do update_question end broadcast(:ok) rescue InvalidStatus broadcast(:invalid) end private attr_reader :question, :current_user def update_question Decidim.traceability.update!( question, current_user, status: new_status(question) ) end def new_status(question) if question.unpublished? Decidim::Meetings::Question.statuses[:published] elsif question.published? Decidim::Meetings::Question.statuses[:closed] else raise InvalidStatus end end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems