app/controllers/decidim/proposals/proposal_votes_controller.rb in decidim-proposals-0.0.2 vs app/controllers/decidim/proposals/proposal_votes_controller.rb in decidim-proposals-0.0.3
- old
+ new
@@ -2,24 +2,35 @@
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!
- before_action :check_current_settings!
def create
- @proposal = Proposal.where(feature: current_feature).find(params[:proposal_id])
- @proposal.votes.create!(author: current_user)
+ authorize! :vote, proposal
+
+ proposal.votes.create!(author: current_user)
@from_proposals_list = params[:from_proposals_list] == "true"
+ render :update_buttons_and_counters
end
+ def destroy
+ authorize! :unvote, proposal
+
+ proposal.votes.where(author: current_user).delete_all
+ @from_proposals_list = params[:from_proposals_list] == "true"
+ render :update_buttons_and_counters
+ end
+
private
- # The vote buttons should not be visible if the setting is not enabled.
- # This ensure the votes cannot be created using a POST request directly.
- def check_current_settings!
- raise "This setting is not enabled for this step" unless current_settings.votes_enabled?
+ def proposal
+ @proposal ||= Proposal.where(feature: current_feature).find(params[:proposal_id])
end
end
end
end