Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable facets knowledge panels for crawlers #8772

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4240,6 +4240,9 @@ HTML
}
# Rendering Page tags
my $tag_html;
# TODO: is_crawl_bot should be added directly by process_template(),
# but we would need to add a new $request_ref parameter to process_template(), will do later
$tag_template_data_ref->{is_crawl_bot} = $request_ref->{is_crawl_bot};
process_template('web/pages/tag/tag.tt.html', $tag_template_data_ref, \$tag_html)
or $tag_html = "<p>tag.tt.html template error: " . $tt->error() . "</p>";

Expand Down
4 changes: 2 additions & 2 deletions templates/web/pages/tag/tag.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ <h2 class="products_title">[% products_title %]</h2>

<div class="large-6 column">
[% IF tagid.defined %]
[% IF facets_kp_url.defined && ! is_crawl_bot %]
<!-- injecting facet-knowledge-panel -->
<div id="facet-knowledge-panel" style="margin-left: 70px;">
<h2 id="facet_panels_title"></h2>
<div id="facet_panels_content"></div>
</div>
<!-- Fetching facet knowledge panel -->
[% IF facets_kp_url.defined %]
<!-- Fetching facet knowledge panel -->
<script>
let facet_kp = "[% facets_kp_url %]";
let params = "?facet_tag=[% tagtype %]&value_tag=[% canon_tagid %]";
Expand Down
25 changes: 23 additions & 2 deletions tests/integration/facet_page_crawler.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ my %product_form = (
(
code => '0200000000235',
product_name => "Only-Product",
categories => "cakes",
)
);

Expand All @@ -40,7 +41,7 @@ my $tests_ref = [
test_case => 'normal-user-access-product-page',
method => 'GET',
path => '/product/0200000000235/only-product',
headers_in => {'User-Agent' => $CRAWLING_BOT_USER_AGENT},
headers_in => {'User-Agent' => $NORMAL_USER_USER_AGENT},
expected_status_code => 200,
expected_type => 'html',
response_content_must_match => '<title>Only-Product - 100 g</title>'
Expand All @@ -50,7 +51,7 @@ my $tests_ref = [
test_case => 'crawler-access-product-page',
method => 'GET',
path => '/product/0200000000235/only-product',
headers_in => {'User-Agent' => $NORMAL_USER_USER_AGENT},
headers_in => {'User-Agent' => $CRAWLING_BOT_USER_AGENT},
expected_status_code => 200,
expected_type => 'html',
response_content_must_match => '<title>Only-Product - 100 g</title>'
Expand Down Expand Up @@ -115,6 +116,26 @@ my $tests_ref = [
expected_type => 'html',
response_content_must_match => 'Unknown user.'
},
# Normal user should get facet knowledge panels
{
test_case => 'normal-user-get-facet-knowledge-panels',
method => 'GET',
path => '/category/cakes',
headers_in => {'User-Agent' => $NORMAL_USER_USER_AGENT},
expected_status_code => 200,
expected_type => 'html',
response_content_must_match => 'Fetching facet knowledge panel'
},
# Crawling bot should have access to product page
{
test_case => 'crawler-does-not-get-facet-knowledge-panels',
method => 'GET',
path => '/category/cakes',
headers_in => {'User-Agent' => $CRAWLING_BOT_USER_AGENT},
expected_status_code => 200,
expected_type => 'html',
response_content_must_not_match => 'Fetching facet knowledge panel'
},
];

execute_api_tests(__FILE__, $tests_ref);
Expand Down
Loading