Skip to content

Commit

Permalink
[bug fix] use default website layout if no app layout is present (#1484)
Browse files Browse the repository at this point in the history
  • Loading branch information
donrestarone and Ayon95 authored Mar 22, 2023
1 parent 916f2aa commit fd1986b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/comfy/admin/cms/layouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/admin/comfy/layouts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fd1986b

Please sign in to comment.