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

Patch the plone.app.redirector.FourOhFourView.search_for_similar #79

Merged
merged 3 commits into from
Oct 9, 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
8 changes: 5 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ Changelog
5.2.5 (unreleased)
------------------

- Nothing changed yet.
- plone.app.redirector.FourOhFourView.search_for_similar patch to enable conditionally
the search for similar
[folix-01]


5.2.4 (2023-09-26)
------------------

- Fix the issue in the @translation GET endpoint: If this
endpoint is invoked, possibly by a bot, and plone.app.multilingual
is not installed, the call will result in an empty search query
endpoint is invoked, possibly by a bot, and plone.app.multilingual
is not installed, the call will result in an empty search query
on the catalog.
[lucabel]

Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ For details see the `pull-request <https://github.com/RedTurtle/redturtle.volto/

This patch is not enabled by default. You need to set an environment variable to `true`: *PROXY_BEARER_AUTH*.

Conditionally search for similar if nonexistent site path passed
----------------------------------------------------------------

plone.app.redirector.FourOhFourView.search_for_similar method patched to return an empty list if
the `REDTURTLE_VOLTO_ENABLE_SEARCH_FOR_SIMILAR` environment variable is set.

New Criteria
============

Expand Down
15 changes: 15 additions & 0 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from zope.globalrequest import getRequest

import datetime
import os


def occurrences(self, range_start=None, range_end=None):
Expand Down Expand Up @@ -144,3 +145,17 @@ def plone_restapi_pam_translations_get(self, expand=False):
if not IPloneAppMultilingualInstalled.providedBy(self.request):
return {"translations": {"@id": f"{self.context.absolute_url()}/@translations"}}
return self._old___call__(expand=expand)


def search_for_similar(*args, **kwargs):
"""plone.app.redirector.browser.FourOhFourView.search_for_similar patch"""

original_obj = args and args[0] or None

if (
os.environ.get("REDTURTLE_VOLTO_ENABLE_SEARCH_FOR_SIMILAR", default=None)
and original_obj
):
return original_obj._old_search_for_similar()

return []
7 changes: 7 additions & 0 deletions src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@
description="Fix long request in case pam is not installed"
preserveOriginal="True"
/>
<monkey:patch
original="search_for_similar"
replacement=".monkey.search_for_similar"
class="plone.app.redirector.browser.FourOhFourView"
description="Cancel the seach_for_similiar call when usin volto frontend"
preserveOriginal="True"
/>

</configure>
Loading