From fd1986b98f499fee1bb8092ef497ee14140bc2bb Mon Sep 17 00:00:00 2001 From: Don Restarone <35935196+donrestarone@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:37:50 -0400 Subject: [PATCH] [bug fix] use default website layout if no app layout is present (#1484) Addresses: #491 https://user-images.githubusercontent.com/73725297/226471380-5f6b07d9-8c8c-40ea-a2af-18d42a9f57a3.mp4 Co-authored-by: Mushfiq Rahman --- app/controllers/comfy/admin/cms/layouts_controller.rb | 9 ++++++++- .../controllers/admin/comfy/layouts_controller_test.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/comfy/admin/cms/layouts_controller.rb b/app/controllers/comfy/admin/cms/layouts_controller.rb index 97244f0b8..3a6154b50 100644 --- a/app/controllers/comfy/admin/cms/layouts_controller.rb +++ b/app/controllers/comfy/admin/cms/layouts_controller.rb @@ -55,8 +55,15 @@ def destroy def build_layout @layout = @site.layouts.new(layout_params) @layout.parent ||= ::Comfy::Cms::Layout.find_by_id(params[:parent_id]) - @layout.app_layout ||= @layout.parent.try(:app_layout) @layout.content ||= "{{ cms:wysiwyg content }}" + + if !@layout.app_layout.blank? + @layout.app_layout = @layout.app_layout + elsif !@layout.parent.nil? + @layout.app_layout = @layout.parent.app_layout + else + @layout.app_layout = "website" + end end def load_layout diff --git a/test/controllers/admin/comfy/layouts_controller_test.rb b/test/controllers/admin/comfy/layouts_controller_test.rb index e7b1b9dbc..d2bf5f008 100644 --- a/test/controllers/admin/comfy/layouts_controller_test.rb +++ b/test/controllers/admin/comfy/layouts_controller_test.rb @@ -66,6 +66,16 @@ class Comfy::Admin::Cms::LayoutsControllerTest < ActionDispatch::IntegrationTest assert_select "form[action='/admin/sites/#{site.id}/layouts']" end + test "default website layout should be used if a newly-created layout has no app_layout and parent" do + @user.update(can_access_admin: true, can_manage_web: true) + sign_in(@user) + get new_comfy_admin_cms_site_layout_url(subdomain: @restarone_subdomain, site_id: @site.id) + + assert_response :success + assert assigns(:layout) + assert_equal "website", assigns(:layout).app_layout + end + test 'denies #new if not permissioned' do sign_in(@user) get new_comfy_admin_cms_site_layout_url(subdomain: @restarone_subdomain, site_id: @site.id)