Skip to content

Commit

Permalink
fix: monkey patch the @translation GET endpoint avoiding a useless se…
Browse files Browse the repository at this point in the history
…arch if plone.app.multilingual is not installed (#77)

fix: monkey patch the @translation GET endpoint avoiding a useless search if plone.app.multilingual is not installed
  • Loading branch information
luca-bellenghi authored Sep 26, 2023
1 parent 2e20bf0 commit 69a23ce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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>

0 comments on commit 69a23ce

Please sign in to comment.