Sha256: 838d01e5b96347b2b60806d99da6a5e5481b1016151cf25d3c9306bf5047d4ef

Contents?: true

Size: 922 Bytes

Versions: 64

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A command with all the business logic when a user unvotes a proposal.
    class UnvoteProposal < Rectify::Command
      # Public: Initializes the command.
      #
      # proposal     - A Decidim::Proposals::Proposal object.
      # 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, together with the proposal.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        destroy_proposal_vote
        broadcast(:ok, @proposal)
      end

      private

      def destroy_proposal_vote
        @proposal.votes.where(author: @current_user).destroy_all
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 2 rubygems

Version Path
decidim-proposals-0.13.1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.12.2 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.13.0 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.12.1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.13.0.pre1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.12.0 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.11.2 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.12.0.pre app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.11.1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.11.0.pre1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.10.1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.10.0 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.9.3 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.9.2 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.9.1 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.9.0 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.8.4 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.8.3 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.8.2 app/commands/decidim/proposals/unvote_proposal.rb
decidim-proposals-0.8.1 app/commands/decidim/proposals/unvote_proposal.rb