app/controllers/decidim/proposals/proposal_votes_controller.rb in decidim-proposals-0.14.4 vs app/controllers/decidim/proposals/proposal_votes_controller.rb in decidim-proposals-0.15.0
- old
+ new
@@ -3,10 +3,11 @@
module Decidim
module Proposals
# Exposes the proposal vote resource so users can vote proposals.
class ProposalVotesController < Decidim::Proposals::ApplicationController
include ProposalVotesHelper
+ include Rectify::ControllerHelpers
helper_method :proposal
before_action :authenticate_user!
@@ -15,10 +16,17 @@
@from_proposals_list = params[:from_proposals_list] == "true"
VoteProposal.call(proposal, current_user) do
on(:ok) do
proposal.reload
+
+ proposals = ProposalVote.where(
+ author: current_user,
+ proposal: Proposal.where(component: current_component)
+ ).map(&:proposal)
+
+ expose(proposals: proposals)
render :update_buttons_and_counters
end
on(:invalid) do
render json: { error: I18n.t("proposal_votes.create.error", scope: "decidim.proposals") }, status: 422
@@ -31,9 +39,16 @@
@from_proposals_list = params[:from_proposals_list] == "true"
UnvoteProposal.call(proposal, current_user) do
on(:ok) do
proposal.reload
+
+ proposals = ProposalVote.where(
+ author: current_user,
+ proposal: Proposal.where(component: current_component)
+ ).map(&:proposal)
+
+ expose(proposals: proposals + [proposal])
render :update_buttons_and_counters
end
end
end