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

Version Path
decidim-plans-0.18.2 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.18.1 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.18.0 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.17.0 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.9 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.8 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.7 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.6 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.5 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.4 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.3 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.2 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.1 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.16.0 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.15.1 app/commands/decidim/plans/destroy_plan.rb
decidim-plans-0.15.0 app/commands/decidim/plans/destroy_plan.rb