Class: Decidim::Elections::VotesController
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
#ballot_questions, #can_preview?, #default_vote_flow, #preview_mode?, #vote_flow
Instance Method Details
#create ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File '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 '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 'app/controllers/decidim/elections/votes_controller.rb', line 46
def show
enforce_permission_to :view, :election, election:
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/decidim/elections/votes_controller.rb', line 50
def update
enforce_permission_to(: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 'app/controllers/decidim/elections/votes_controller.rb', line 64
def verify
enforce_permission_to(:view, :election, election:)
@form = form(Voter::VerifyVoteForm).instance(election:)
end
|