Class: Decidim::Proposals::ProposalVotesController

Inherits:
ApplicationController show all
Includes:
ProposalVotesHelper, Rectify::ControllerHelpers
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 ProposalVotesHelper

#can_accumulate_supports_beyond_threshold?, #current_user_can_vote?, #remaining_votes_count_for, #threshold_per_proposal, #threshold_per_proposal_enabled?, #vote_button_classes, #vote_limit, #vote_limit_enabled?, #votes_blocked?, #votes_count_classes, #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, #share_token

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


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
  enforce_permission_to :vote, :proposal, 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: 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

#destroyObject


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
  enforce_permission_to :unvote, :proposal, 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