Sha256: b728461c4e891b6c66a94b431b44567902cbd18a374059c983b97a82d43d4e0a

Contents?: true

Size: 974 Bytes

Versions: 7

Compression:

Stored size: 974 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 < Rectify::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) if @proposal.author != @current_user

        @proposal.destroy!

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-proposals-0.12.2 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.12.1 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.12.0 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.11.2 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.12.0.pre app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.11.1 app/commands/decidim/proposals/destroy_proposal.rb
decidim-proposals-0.11.0.pre1 app/commands/decidim/proposals/destroy_proposal.rb