Sha256: 1f451e2369a08878c8563d5b1c0526800780cb6e1c90937c2dc86dd9f1784ea1
Contents?: true
Size: 1.25 KB
Versions: 7
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Decidim module Plans # A command with all the business logic when a user reopens a plan. class ReopenPlan < Rectify::Command # Public: Initializes the command. # # plan - The plan to publish. # current_user - The current user. def initialize(plan, current_user) @plan = plan @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid and the plan is published. # - :invalid if the plan's author is not the current user. # # Returns nothing. def call return broadcast(:invalid) if @current_user.nil? close_plan broadcast(:ok, @plan) end private def close_plan Decidim.traceability.perform_action!( "reopen", @plan, @current_user, visibility: "public-only" ) do # Unless the plan has already been answered, change the state back to # "open". state = @plan.state state = "open" unless @plan.answered? @plan.update!( state: state, closed_at: nil ) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems