Class: Decidim::Proposals::ProposalVotesController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- Components::BaseController
- ApplicationController
- Decidim::Proposals::ProposalVotesController
- Includes:
- ControllerHelpers, ProposalVotesHelper
- Defined in:
- decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
Overview
Exposes the proposal vote resource so users can vote proposals.
Instance Method Summary collapse
Methods included from ControllerHelpers
#expose, included, #present, #presenter
Methods included from ProposalVotesHelper
#can_accumulate_supports_beyond_threshold?, #current_user_can_vote?, #remaining_votes_count_for, #threshold_per_proposal, #threshold_per_proposal_enabled?, #vote_limit, #vote_limit_enabled?, #votes_blocked?, #votes_enabled?
Methods inherited from ApplicationController
#proposal_limit, #proposal_limit_reached?, #proposals
Methods inherited from Components::BaseController
#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item, #share_token
Methods included from RegistersPermissions
Methods included from UserBlockedChecker
#check_user_block_status, #check_user_not_blocked
Methods included from NeedsSnippets
Methods included from Headers::HttpCachingDisabler
Methods included from HasStoredPath
#skip_store_location?, #store_current_location
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb', line 14 def create (:vote, :proposal, proposal:) @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:) render :update_buttons_and_counters end on(:invalid) do render json: { error: I18n.t("proposal_votes.create.error", scope: "decidim.proposals") }, status: :unprocessable_entity end end end |
#destroy ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb', line 37 def destroy (:unvote, :proposal, proposal:) @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 |