From 594026d65ffe1e133a1bc4e4e8d77819f364ad60 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 25 Apr 2024 22:41:57 +0100 Subject: [PATCH] FIX: Include HTML content for authenticated users with crawler UA (#26757) e05628c0 introduced an optimization to remove basic-HTML content for authenticated users. The assumption is that, if they were able to log in, they must have a JS capable browser and do not need the basic HTML. However, there are use-cases where an API-key is used to crawl a private site, or private categories of a public site. This commit re-enables those use cases by keeping the basic-html in place for crawler/bot user agents. --- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d5b5794d66..b409efe2183 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -431,7 +431,7 @@ module ApplicationHelper end def include_crawler_content? - if current_user + if current_user && !crawler_layout? params.key?(:print) else crawler_layout? || !mobile_view? || !modern_mobile_device? diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 040722f48e3..561005784b7 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -19,11 +19,19 @@ RSpec.describe ApplicationHelper do it "sends crawler content to logged on users who wants to print" do helper.stubs(:current_user).returns(Fabricate(:user)) + controller.stubs(:use_crawler_layout?).returns(false) helper.stubs(:params).returns(print: true) expect(helper.include_crawler_content?).to eq(true) end + it "sends crawler content to logged on users with a crawler user agent" do + helper.stubs(:current_user).returns(Fabricate(:user)) + controller.stubs(:use_crawler_layout?).returns(true) + + expect(helper.include_crawler_content?).to eq(true) + end + it "sends crawler content to old mobiles" do controller.stubs(:use_crawler_layout?).returns(false)