Sha256: cc9dfe2c1ab4becc3712b93bfab806d99732f4f1c23de6659a68029aeb409577
Contents?: true
Size: 926 Bytes
Versions: 16
Compression:
Stored size: 926 Bytes
Contents
# frozen_string_literal: true module Decidim module Plans # A command with all the business logic when a user destroys a draft plan. class DestroyPlan < Rectify::Command # Public: Initializes the command. # # plan - The plan to destroy. # 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 deleted. # - :invalid if the plan is not a draft. # - :invalid if the plan's author is not the current user. # # Returns nothing. def call return broadcast(:invalid) unless @plan.draft? return broadcast(:invalid) unless @plan.authored_by?(@current_user) @plan.destroy! broadcast(:ok, @plan) end end end end
Version data entries
16 entries across 16 versions & 1 rubygems