diff --git a/app/controllers/alchemy/admin/layoutpages_controller.rb b/app/controllers/alchemy/admin/layoutpages_controller.rb
index c53a5a94e4..2bf2995593 100644
--- a/app/controllers/alchemy/admin/layoutpages_controller.rb
+++ b/app/controllers/alchemy/admin/layoutpages_controller.rb
@@ -17,6 +17,25 @@ def index
def edit
@page = Page.find(params[:id])
end
+
+ def update
+ @page = Page.find(params[:id])
+ if @page.update(page_params)
+ @notice = Alchemy.t("Page saved", name: @page.name)
+ render "alchemy/admin/pages/update"
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ private
+
+ def page_params
+ params.require(:page).permit(
+ :name,
+ :tag_list
+ )
+ end
end
end
end
diff --git a/app/views/alchemy/admin/layoutpages/edit.html.erb b/app/views/alchemy/admin/layoutpages/edit.html.erb
index 8e07640b16..200a6578da 100644
--- a/app/views/alchemy/admin/layoutpages/edit.html.erb
+++ b/app/views/alchemy/admin/layoutpages/edit.html.erb
@@ -1,4 +1,4 @@
-<%= alchemy_form_for [:admin, @page], class: 'edit_page' do |f| %>
+<%= alchemy_form_for [:admin, @page], url: alchemy.admin_layoutpage_path(@page), class: 'edit_page' do |f| %>
<%= f.input :name, autofocus: true %>
<%= f.label :tag_list %>
diff --git a/config/routes.rb b/config/routes.rb
index 21e50dd0c4..7f023e6337 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -49,7 +49,7 @@
end
end
- resources :layoutpages, only: [:index, :edit]
+ resources :layoutpages, only: [:index, :edit, :update]
resources :pictures, except: [:new] do
collection do
diff --git a/lib/alchemy/permissions.rb b/lib/alchemy/permissions.rb
index 9eec7cd772..585ce0b458 100644
--- a/lib/alchemy/permissions.rb
+++ b/lib/alchemy/permissions.rb
@@ -96,7 +96,7 @@ def alchemy_author_rules
can :leave, :alchemy_admin
can [:info, :help], :alchemy_admin_dashboard
can :manage, :alchemy_admin_clipboard
- can :edit, :alchemy_admin_layoutpages
+ can :update, :alchemy_admin_layoutpages
can :tree, :alchemy_admin_pages
# Resources
diff --git a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb
index a39b5322b9..f344edb188 100644
--- a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb
+++ b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb
@@ -62,5 +62,29 @@ module Alchemy
end
end
end
+
+ describe "#update" do
+ let(:page) { create(:alchemy_page, :layoutpage) }
+
+ context "with passing validations" do
+ subject { put :update, params: {id: page.id, page: {name: "New Name"}}, format: :js }
+
+ it "renders update template" do
+ is_expected.to render_template("alchemy/admin/pages/update")
+ end
+ end
+
+ context "with failing validations" do
+ subject { put :update, params: {id: page.id, page: {name: ""}} }
+
+ it "renders edit form" do
+ is_expected.to render_template(:edit)
+ end
+
+ it "sets 422 status" do
+ expect(subject.status).to eq 422
+ end
+ end
+ end
end
end
diff --git a/spec/libraries/permissions_spec.rb b/spec/libraries/permissions_spec.rb
index 693fac00c2..fb1e85d352 100644
--- a/spec/libraries/permissions_spec.rb
+++ b/spec/libraries/permissions_spec.rb
@@ -148,6 +148,10 @@
is_expected.to be_able_to(:switch, Alchemy::Language)
end
+ it "can update layoutpages" do
+ is_expected.to be_able_to(:update, :alchemy_admin_layoutpages)
+ end
+
context "if page language is public" do
let(:language) { create(:alchemy_language, :german, public: true) }
let(:page) { create(:alchemy_page, language: language) }