Class: Decidim::Admin::StaticPagesController
Overview
Controller that allows managing all pages 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
#content_block_scope ⇒ Object
18
19
20
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 18
def content_block_scope
:static_page
end
|
#create ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 53
def create
enforce_permission_to :create, :static_page
@form = form(StaticPageForm).from_params(form_params)
CreateStaticPage.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("static_pages.create.success", scope: "decidim.admin")
redirect_to static_pages_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("static_pages.create.error", scope: "decidim.admin")
render :new
end
end
end
|
#destroy ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 93
def destroy
enforce_permission_to :destroy, :static_page, static_page: page
Decidim::Commands::DestroyResource.call(page, current_user) do
on(:ok) do
flash[:notice] = I18n.t("static_pages.destroy.success", scope: "decidim.admin")
redirect_to static_pages_path
end
end
end
|
#edit ⇒ Object
70
71
72
73
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 70
def edit
enforce_permission_to :update, :static_page, static_page: page
@form = form(StaticPageForm).from_model(page)
end
|
#enforce_permission_to_update_resource ⇒ Object
26
27
28
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 26
def enforce_permission_to_update_resource
enforce_permission_to :update, :static_page, static_page: scoped_resource
end
|
#index ⇒ Object
42
43
44
45
46
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 42
def index
enforce_permission_to :read, :static_page
@topics = Decidim::StaticPageTopic.where(organization: current_organization)
@orphan_pages = collection.where(topic: nil)
end
|
#new ⇒ Object
48
49
50
51
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 48
def new
enforce_permission_to :create, :static_page
@form = form(StaticPageForm).instance
end
|
#resource_content_block_cell ⇒ Object
38
39
40
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 38
def resource_content_block_cell
"decidim/admin/static_page_content_block"
end
|
#resource_create_url(manifest_name) ⇒ Object
34
35
36
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 34
def resource_create_url(manifest_name)
static_page_content_blocks_path(scoped_resource, manifest_name:)
end
|
#resource_sort_url ⇒ Object
30
31
32
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 30
def resource_sort_url
update_content_blocks_static_page_path(scoped_resource)
end
|
#scoped_resource ⇒ Object
22
23
24
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 22
def scoped_resource
@scoped_resource ||= collection.find_by(slug: params[:id])
end
|
#update ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 75
def update
@page = collection.find(params[:id])
enforce_permission_to :update, :static_page, static_page: page
@form = form(StaticPageForm).from_params(form_params)
UpdateStaticPage.call(@form, page) do
on(:ok) do
flash[:notice] = I18n.t("static_pages.update.success", scope: "decidim.admin")
redirect_to static_pages_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("static_pages.update.error", scope: "decidim.admin")
render :edit
end
end
end
|
#update_content_blocks ⇒ Object
16
|
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 16
alias update_content_blocks update
|