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: use pam layer in pam services #1723

Merged
merged 3 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions news/1723.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
limits the use of multilingual services only if multilingual is actually installed. @mamico
4 changes: 4 additions & 0 deletions src/plone/restapi/services/multilingual/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
factory=".pam.TranslationInfo"
for="Products.CMFCore.interfaces.IContentish"
permission="zope2.View"
layer="plone.app.multilingual.interfaces.IPloneAppMultilingualInstalled"
name="@translations"
/>
<cache:ruleset
Expand All @@ -33,6 +34,7 @@
factory=".pam.LinkTranslations"
for="Products.CMFCore.interfaces.IContentish"
permission="plone.app.multilingual.ManageTranslations"
layer="plone.app.multilingual.interfaces.IPloneAppMultilingualInstalled"
name="@translations"
/>

Expand All @@ -41,6 +43,7 @@
factory=".pam.UnlinkTranslations"
for="Products.CMFCore.interfaces.IContentish"
permission="plone.app.multilingual.ManageTranslations"
layer="plone.app.multilingual.interfaces.IPloneAppMultilingualInstalled"
name="@translations"
/>

Expand All @@ -49,6 +52,7 @@
factory=".locator.TranslationLocator"
for="Products.CMFCore.interfaces.IContentish"
permission="plone.app.multilingual.ManageTranslations"
layer="plone.app.multilingual.interfaces.IPloneAppMultilingualInstalled"
name="@translation-locator"
/>

Expand Down
28 changes: 28 additions & 0 deletions src/plone/restapi/tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from plone.restapi.bbb import ILanguage
from plone.restapi.testing import PLONE_RESTAPI_DX_PAM_FUNCTIONAL_TESTING
from plone.restapi.testing import PLONE_RESTAPI_DX_PAM_INTEGRATION_TESTING
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from zope.component import getMultiAdapter
from zope.interface import alsoProvides

Expand Down Expand Up @@ -374,3 +375,30 @@ def test_translation_locator(self):
self.assertEqual(200, response.status_code)

self.assertEqual(self.portal_url + "/de", response.json().get("@id"))


class TestPAMNotinstalled(unittest.TestCase):
layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

def setUp(self):
self.portal = self.layer["portal"]
self.request = self.layer["request"]
login(self.portal, SITE_OWNER_NAME)
self.folder = createContentInContainer(self.portal, "Folder", title="Folder")
transaction.commit()

def test_translations(self):
response = requests.get(
f"{self.folder.absolute_url()}/@translations",
headers={"Accept": "application/json"},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
)
self.assertEqual(404, response.status_code)

def test_translation_locator(self):
response = requests.get(
f"{self.folder.absolute_url()}/@translation-locator",
headers={"Accept": "application/json"},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
)
self.assertEqual(404, response.status_code)