Sha256: 1af1cf70cd2f68c774e42ae25ea42728c71f824a2d39ca156bc26f78af903035

Contents?: true

Size: 982 Bytes

Versions: 25

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A command with all the business logic when a user destroys a draft proposal.
    class DestroyProposal < Decidim::Command
      # Public: Initializes the command.
      #
      # proposal     - The proposal to destroy.
      # current_user - The current user.
      def initialize(proposal, current_user)
        @proposal = proposal
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid and the proposal is deleted.
      # - :invalid if the proposal is not a draft.
      # - :invalid if the proposal's author is not the current user.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless @proposal.draft?
        return broadcast(:invalid) unless @proposal.authored_by?(@current_user)

        @proposal.destroy!

        broadcast(:ok, @proposal)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-proposals-0.29.1 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.4 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.9 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.29.0 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.3 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.8 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.29.0.rc4 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.29.0.rc3 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.29.0.rc2 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.29.0.rc1 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.2 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.7 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.1 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.6 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.0 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.5 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.0.rc5 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.28.0.rc4 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.4 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.27.3 app/commands/decidim/proposals/destroy_proposal.rb