Class: Decidim::Admin::AreasController
Overview
Controller that allows managing all areas at the admin panel.
Instance Method Summary
collapse
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
Instance Method Details
#create ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 26
def create
enforce_permission_to :create, :area
@form = form(AreaForm).from_params(params)
CreateArea.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("areas.create.success", scope: "decidim.admin")
redirect_to areas_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("areas.create.error", scope: "decidim.admin")
render :new
end
end
end
|
#destroy ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 64
def destroy
enforce_permission_to(:destroy, :area, area:)
DestroyArea.call(area, current_user) do
on(:ok) do
flash[:notice] = I18n.t("areas.destroy.success", scope: "decidim.admin")
redirect_to areas_path
end
on(:has_spaces) do
flash[:alert] = I18n.t("areas.destroy.has_spaces", scope: "decidim.admin")
redirect_to areas_path
end
end
end
|
#edit ⇒ Object
42
43
44
45
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 42
def edit
enforce_permission_to(:update, :area, area:)
@form = form(AreaForm).from_model(area)
end
|
#index ⇒ Object
16
17
18
19
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 16
def index
enforce_permission_to :read, :area
@areas = organization_areas
end
|
#new ⇒ Object
21
22
23
24
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 21
def new
enforce_permission_to :create, :area
@form = form(AreaForm).instance
end
|
#update ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/decidim/admin/areas_controller.rb', line 47
def update
enforce_permission_to(:update, :area, area:)
@form = form(AreaForm).from_params(params)
UpdateArea.call(@form, area) do
on(:ok) do
flash[:notice] = I18n.t("areas.update.success", scope: "decidim.admin")
redirect_to areas_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("areas.update.error", scope: "decidim.admin")
render :edit
end
end
end
|