Class: Decidim::Votings::VotingsController

Inherits:
ApplicationController show all
Includes:
Elections::HasVoteFlow, NeedsVoting, Orderable, FilterResource, FormFactory, Paginable, ParticipatorySpaceContext
Defined in:
app/controllers/decidim/votings/votings_controller.rb

Overview

A controller that holds the logic to show votings in a public layout.

Instance Method Summary collapse

Methods included from Elections::HasVoteFlow

#ballot_questions, #can_preview?, #default_vote_flow, #preview_mode?, #vote_flow

Methods included from NeedsVoting

enhance_controller, included

Instance Method Details

#check_censusObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/decidim/votings/votings_controller.rb', line 56

def check_census
  @form = form(Census::CheckForm).from_params(params).with_context(
    current_participatory_space: current_participatory_space
  )

  success = not_found = false
  datum = nil
  CheckCensus.call(@form) do
    on(:ok) do |census|
      success = true
      datum = census
    end
    on(:not_found) do
      not_found = true
    end
    on(:invalid) do
      flash[:alert] = t("check_census.invalid", scope: "decidim.votings.votings")
    end
  end

  render action: :check_census, locals: { success: success, not_found: not_found, datum: datum }
end

#elections_logObject



91
92
93
# File 'app/controllers/decidim/votings/votings_controller.rb', line 91

def elections_log
  redirect_to election_log_path(elections.first) if elections.length == 1
end

#indexObject

Raises:

  • (ActionController::RoutingError)


29
30
31
32
33
34
# File 'app/controllers/decidim/votings/votings_controller.rb', line 29

def index
  raise ActionController::RoutingError, "Not Found" if published_votings.none?

  enforce_permission_to :read, :votings
  redirect_to voting_path(single) if single?
end

#loginObject



44
45
46
47
48
49
# File 'app/controllers/decidim/votings/votings_controller.rb', line 44

def 
  @form = form(Census::LoginForm).from_params(params, election: election)

  render :login,
         layout: "decidim/election_votes"
end

#send_access_codeObject



79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/decidim/votings/votings_controller.rb', line 79

def send_access_code
  SendAccessCode.call(datum, params[:medium]) do
    on(:ok) do
      flash[:notice] = t("send_access_code.success", scope: "decidim.votings.votings")
    end
    on(:invalid) do
      flash[:alert] = t("send_access_code.invalid", scope: "decidim.votings.votings")
    end
  end
  render action: :check_census, locals: { success: true, not_found: false, datum: datum }
end

#showObject

Raises:

  • (ActionController::RoutingError)


36
37
38
39
40
# File 'app/controllers/decidim/votings/votings_controller.rb', line 36

def show
  raise ActionController::RoutingError, "Not Found" unless current_participatory_space

  enforce_permission_to :read, :voting, voting: current_participatory_space
end

#show_check_censusObject



51
52
53
54
# File 'app/controllers/decidim/votings/votings_controller.rb', line 51

def show_check_census
  @form = form(Census::CheckForm).instance
  render :check_census, locals: { success: false, not_found: false }
end