Sha256: 8b021a88c59b700f9a8137fb46b49b7c363694acf614a2880defcb0cf57e9b1b

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # Exposes the proposal vote resource so users can vote proposals.
    class ProposalVotesController < Decidim::Proposals::ApplicationController
      include ProposalVotesHelper

      helper_method :proposal

      before_action :authenticate_user!

      def create
        authorize! :vote, proposal
        @from_proposals_list = params[:from_proposals_list] == "true"

        VoteProposal.call(proposal, current_user) do
          on(:ok) do
            proposal.reload
            render :update_buttons_and_counters
          end

          on(:invalid) do
            render json: { error: I18n.t("proposal_votes.create.error", scope: "decidim.proposals") }, status: 422
          end
        end
      end

      def destroy
        authorize! :unvote, proposal
        @from_proposals_list = params[:from_proposals_list] == "true"

        UnvoteProposal.call(proposal, current_user) do
          on(:ok) do
            proposal.reload
            render :update_buttons_and_counters
          end
        end
      end

      private

      def proposal
        @proposal ||= Proposal.where(component: current_component).find(params[:proposal_id])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-proposals-0.11.2 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.11.1 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.11.0.pre1 app/controllers/decidim/proposals/proposal_votes_controller.rb