Class: Decidim::Votings::Admin::MonitoringCommitteeElectionResultsController

Inherits:
ApplicationController show all
Includes:
VotingAdmin
Defined in:
decidim-elections/app/controllers/decidim/votings/admin/monitoring_committee_election_results_controller.rb

Overview

This controller allows a monitoring committee member to list and validate the polling stations closures.

Instance Method Summary collapse

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#indexObject


12
13
14
15
16
# File 'decidim-elections/app/controllers/decidim/votings/admin/monitoring_committee_election_results_controller.rb', line 12

def index
  enforce_permission_to :read, :monitoring_committee_election_results, voting: current_voting

  redirect_to voting_monitoring_committee_election_result_path(current_voting, elections.first) if elections.one?
end

#showObject


18
19
20
# File 'decidim-elections/app/controllers/decidim/votings/admin/monitoring_committee_election_results_controller.rb', line 18

def show
  enforce_permission_to :read, :monitoring_committee_election_result, voting: current_voting, election: election
end

#updateObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'decidim-elections/app/controllers/decidim/votings/admin/monitoring_committee_election_results_controller.rb', line 22

def update
  enforce_permission_to :validate, :monitoring_committee_election_result, voting: current_voting, election: election

  if publish_results_form.pending_action
    Decidim::Elections::Admin::UpdateActionStatus.call(publish_results_form.pending_action)

    if publish_results_form.pending_action.accepted?
      flash[:notice] = I18n.t("monitoring_committee_election_results.update.success", scope: "decidim.votings.admin")
    else
      flash[:alert] = I18n.t("monitoring_committee_election_results.update.rejected", scope: "decidim.votings.admin")
    end

    return redirect_to voting_monitoring_committee_election_result_path(current_voting, election)
  end

  Decidim::Elections::Admin::PublishResults.call(publish_results_form) do
    on(:invalid) do
      flash.now[:alert] = I18n.t("monitoring_committee_election_results.update.invalid", scope: "decidim.votings.admin")
    end
    on(:ok) do
      publish_results_form.refresh
    end
  end

  render :show
end