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: monkey patch the @translation GET endpoint avoiding a useless search if plone.app.multilingual is not installed #77

Merged
merged 2 commits into from
Sep 26, 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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
5.2.4 (unreleased)
------------------

- 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
on the catalog.
[lucabel]

- backport https://github.com/plone/Products.CMFPlone/pull/3845
fix: avoid searching all users when many_users is flagged
[mamico]
Expand Down
12 changes: 12 additions & 0 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from plone.app.caching import purge
from plone.app.event.base import dt_start_of_day
from plone.app.event.recurrence import Occurrence
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
from plone.event.interfaces import IEventAccessor
from plone.event.recurrence import recurrence_sequence_ical
from plone.event.utils import pydt
Expand Down Expand Up @@ -132,3 +133,14 @@ def getPotentialMembers(self, searchString):
if findAll or searchString:
return self._old_getPotentialMembers(searchString)
return []


def plone_restapi_pam_translations_get(self, expand=False):
"""If plone.app.multilingual is not installed get_restricted_translations will
search for the translations in the portal catalog with the unexisting index
TranslationsGruop. this measn that the method will iterate over the whole
catalog. We need to check if the method is available before calling it.
"""
if not IPloneAppMultilingualInstalled.providedBy(self.request):
return {"translations": {"@id": f"{self.context.absolute_url()}/@translations"}}
return self._old___call__(expand=expand)
8 changes: 8 additions & 0 deletions src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@
preserveOriginal="True"
/>

<monkey:patch
original="__call__"
replacement=".monkey.plone_restapi_pam_translations_get"
class="plone.restapi.services.multilingual.pam.Translations"
description="Fix long request in case pam is not installed"
preserveOriginal="True"
/>

</configure>
Loading