Class: Decidim::Elections::VotesController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- Components::BaseController
- ApplicationController
- Decidim::Elections::VotesController
- Includes:
- HasVoteFlow, FormFactory
- Defined in:
- decidim-elections/app/controllers/decidim/elections/votes_controller.rb
Overview
Exposes the elections resources so users can participate on them
Constant Summary collapse
- WIZARD_STEPS =
%w(register election confirm ballot_decision).freeze
Instance Method Summary collapse
Methods included from HasVoteFlow
#ballot_questions, #can_preview?, #default_vote_flow, #preview_mode?, #vote_flow
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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'decidim-elections/app/controllers/decidim/elections/votes_controller.rb', line 27 def create vote_flow.voter_from_token(params.require(:vote).permit(:voter_token, :voter_id)) return unless valid_voter_token? return unless vote_allowed? return redirect_to election_vote_path(election, id: params[:vote][:encrypted_data_hash], token: vote_flow.voter_id_token) if preview_mode? @form = form(Voter::VoteForm).from_params(params, election:, user: vote_flow.user, email: vote_flow.email) Voter::CastVote.call(@form) do on(:ok) do |vote| redirect_to election_vote_path(election, id: vote.encrypted_vote_hash, token: vote_flow.voter_id_token) end on(:invalid) do flash[:alert] = I18n.t("votes.create.error", scope: "decidim.elections") redirect_to exit_path end end end |
#new ⇒ Object
19 20 21 22 23 24 25 |
# File 'decidim-elections/app/controllers/decidim/elections/votes_controller.rb', line 19 def new vote_flow.voter_login(params) return unless vote_allowed? @form = form(Voter::VoteForm).from_params({ voter_token:, voter_id: }, election:, user: vote_flow.user) end |
#show ⇒ Object
46 47 48 |
# File 'decidim-elections/app/controllers/decidim/elections/votes_controller.rb', line 46 def show :view, :election, election: end |
#update ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'decidim-elections/app/controllers/decidim/elections/votes_controller.rb', line 50 def update (:view, :election, election:) Voter::UpdateVoteStatus.call(vote) do on(:ok) do redirect_to election_vote_path(election, id: vote.encrypted_vote_hash, token: vote_flow.voter_id_token(vote.voter_id)) end on(:invalid) do flash[:alert] = I18n.t("votes.update.error", scope: "decidim.elections") redirect_to exit_path end end end |
#verify ⇒ Object
64 65 66 67 68 |
# File 'decidim-elections/app/controllers/decidim/elections/votes_controller.rb', line 64 def verify (:view, :election, election:) @form = form(Voter::VerifyVoteForm).instance(election:) end |