Class: Decidim::Elections::Admin::ElectionsController
Overview
This controller allows the create or update an election.
Instance Method Summary
collapse
#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #set_component_breadcrumb_item, #skip_manage_component_permission
register_permissions
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
#disable_http_caching
#snippets
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 19
def create
enforce_permission_to :create, :election
@form = form(ElectionForm).from_params(params, current_component:)
CreateElection.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("elections.create.success", scope: "decidim.elections.admin")
redirect_to elections_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("elections.create.invalid", scope: "decidim.elections.admin")
render action: "new"
end
end
end
|
#destroy ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 58
def destroy
enforce_permission_to(:delete, :election, election:)
DestroyElection.call(election, current_user) do
on(:ok) do
flash[:notice] = I18n.t("elections.destroy.success", scope: "decidim.elections.admin")
end
on(:invalid) do
flash[:alert] = I18n.t("elections.destroy.invalid", scope: "decidim.elections.admin")
end
end
redirect_to elections_path
end
|
#edit ⇒ Object
36
37
38
39
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 36
def edit
enforce_permission_to(:update, :election, election:)
@form = form(ElectionForm).from_model(election)
end
|
#index ⇒ Object
10
11
12
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 10
def index
flash.now[:alert] ||= I18n.t("elections.index.no_bulletin_board", scope: "decidim.elections.admin").html_safe unless Decidim::Elections.bulletin_board.configured?
end
|
#new ⇒ Object
14
15
16
17
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 14
def new
enforce_permission_to :create, :election
@form = form(ElectionForm).instance
end
|
#publish ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 74
def publish
enforce_permission_to(:publish, :election, election:)
PublishElection.call(election, current_user) do
on(:ok) do
flash[:notice] = I18n.t("admin.elections.publish.success", scope: "decidim.elections")
redirect_to elections_path
end
end
end
|
#unpublish ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 85
def unpublish
enforce_permission_to(:unpublish, :election, election:)
UnpublishElection.call(election, current_user) do
on(:ok) do
flash[:notice] = I18n.t("admin.elections.unpublish.success", scope: "decidim.elections")
redirect_to elections_path
end
end
end
|
#update ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'decidim-elections/app/controllers/decidim/elections/admin/elections_controller.rb', line 41
def update
enforce_permission_to(:update, :election, election:)
@form = form(ElectionForm).from_params(params, current_component:)
UpdateElection.call(@form, election) do
on(:ok) do
flash[:notice] = I18n.t("elections.update.success", scope: "decidim.elections.admin")
redirect_to elections_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("elections.update.invalid", scope: "decidim.elections.admin")
render action: "edit"
end
end
end
|