Class: Decidim::Votings::VotingsController

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

Overview

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

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

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

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 Headers::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

#check_censusObject

Raises:

  • (ActionController::RoutingError)


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

def check_census
  raise ActionController::RoutingError, "Not Found" unless current_participatory_space.check_census_enabled?

  @form = form(Census::CheckForm).from_params(params).with_context(
    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:, not_found:, datum: }
end

#elections_logObject



93
94
95
# File 'decidim-elections/app/controllers/decidim/votings/votings_controller.rb', line 93

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

#indexObject

Raises:

  • (ActionController::RoutingError)


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

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



43
44
45
46
47
# File 'decidim-elections/app/controllers/decidim/votings/votings_controller.rb', line 43

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

  render :login
end

#send_access_codeObject



81
82
83
84
85
86
87
88
89
90
91
# File 'decidim-elections/app/controllers/decidim/votings/votings_controller.rb', line 81

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: }
end

#showObject

Raises:

  • (ActionController::RoutingError)


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

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

  enforce_permission_to :read, :voting, voting: current_participatory_space
end

#show_check_censusObject

Raises:

  • (ActionController::RoutingError)


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

def show_check_census
  raise ActionController::RoutingError, "Not Found" unless current_participatory_space.check_census_enabled?

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