Class: Decidim::Votings::Admin::PollingOfficersController

Inherits:
ApplicationController show all
Includes:
PollingOfficers::Admin::Filterable, VotingAdmin
Defined in:
decidim-elections/app/controllers/decidim/votings/admin/polling_officers_controller.rb

Overview

This controller allows to create or update a polling officer.

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

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-elections/app/controllers/decidim/votings/admin/polling_officers_controller.rb', line 18

def create
  enforce_permission_to :create, :polling_officer, voting: current_voting
  @form = form(VotingUserRoleForm).from_params(params, voting: current_voting)

  CreatePollingOfficer.call(@form, current_user, current_voting) do
    on(:ok) do
      flash[:notice] = I18n.t("polling_officers.create.success", scope: "decidim.votings.admin")
      redirect_to voting_polling_officers_path(current_voting)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("polling_officers.create.invalid", scope: "decidim.votings.admin")
      render action: "new"
    end
  end
end

#destroyObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'decidim-elections/app/controllers/decidim/votings/admin/polling_officers_controller.rb', line 35

def destroy
  enforce_permission_to(:delete, :polling_officer, voting: current_voting, polling_officer:)

  DestroyPollingOfficer.call(polling_officer, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("polling_officers.destroy.success", scope: "decidim.votings.admin")
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("polling_officers.destroy.invalid", scope: "decidim.votings.admin")
    end
  end

  redirect_to voting_polling_officers_path(current_voting)
end

#newObject



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

def new
  enforce_permission_to :create, :polling_officer, voting: current_voting
  @form = form(VotingUserRoleForm).instance
end