diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js index 78b9dc698d2..5895f2df87c 100644 --- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js +++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js @@ -38,7 +38,12 @@ export default { preloaded = JSON.parse(preloadedDataElement.dataset.preloaded); } - Object.keys(preloaded).forEach(function (key) { + const keys = Object.keys(preloaded); + if (keys.length === 0) { + throw "No preload data found in #data-preloaded. Unable to boot Discourse."; + } + + keys.forEach(function (key) { PreloadStore.store(key, JSON.parse(preloaded[key])); if (setupData.debugPreloadedAppData === "true") { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f02aff3ee5..94e3808bc1d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -339,7 +339,7 @@ class ApplicationController < ActionController::Base return render plain: message, status: status_code end with_resolved_locale do - error_page_opts[:layout] = opts[:include_ember] ? 'application' : 'no_ember' + error_page_opts[:layout] = (opts[:include_ember] && @preloaded) ? 'application' : 'no_ember' render html: build_not_found_page(error_page_opts) end end diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index f975533ed21..550e35b8c87 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -2000,12 +2000,19 @@ describe PostsController do expect(response).to be_redirect end - it "returns a 403 when access is denied" do + it "returns a 403 when access is denied for JSON format" do post = Fabricate(:private_message_post) get "/p/#{post.id}.json" expect(response).to be_forbidden end + it "returns a 403 when access is denied for HTML format" do + post = Fabricate(:private_message_post) + get "/p/#{post.id}" + expect(response).to be_forbidden + expect(response.body).to have_tag("body.no-ember") + end + it "renders a 404 page" do get "/p/0" expect(response.status).to eq(404)