diff --git a/src/design/plone/contenttypes/restapi/serializers/dxfields.py b/src/design/plone/contenttypes/restapi/serializers/dxfields.py index fb11bef5..1e83e64e 100644 --- a/src/design/plone/contenttypes/restapi/serializers/dxfields.py +++ b/src/design/plone/contenttypes/restapi/serializers/dxfields.py @@ -10,7 +10,7 @@ from plone.dexterity.interfaces import IDexterityContent from plone.namedfile.interfaces import INamedFileField from plone.namedfile.interfaces import INamedImageField -from plone.outputfilters.browser.resolveuid import uuidToURL +from plone.app.uuid.utils import uuidToURL, uuidToObject from plone.restapi.interfaces import IBlockFieldSerializationTransformer from plone.restapi.interfaces import IFieldSerializer from plone.restapi.interfaces import ISerializeToJsonSummary @@ -198,7 +198,13 @@ def __call__(self): match = RESOLVEUID_RE.match(path) if match: uid, suffix = match.groups() - value = uuidToURL(uid) + if api.user.is_anonymous(): + target = uuidToObject(uid, unrestricted=True) + value = target.absolute_url() + if not api.user.has_permission("View", obj=target): + value = f"{value}/login" + else: + value = uuidToURL(uid) else: portal = getMultiAdapter( (self.context, self.context.REQUEST), name="plone_portal_state" diff --git a/src/design/plone/contenttypes/tests/test_ct_servizio.py b/src/design/plone/contenttypes/tests/test_ct_servizio.py index b170b827..e0f3cdc7 100644 --- a/src/design/plone/contenttypes/tests/test_ct_servizio.py +++ b/src/design/plone/contenttypes/tests/test_ct_servizio.py @@ -354,8 +354,12 @@ def setUp(self): self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + self.api_session_anon = RelativeSession(self.portal_url) + self.api_session_anon.headers.update({"Accept": "application/json"}) + def tearDown(self): self.api_session.close() + self.api_session_anon.close() def test_related_widgets(self): response = self.api_session.get("/@types/Servizio") @@ -482,11 +486,15 @@ def test_canale_digitale_link_serialized_as_url(self): title="Test servizio", canale_digitale_link="/plone/resolveuid/{}".format(page.UID()), ) - + api.content.transition(obj=servizio, transition="publish") commit() + res = self.api_session.get(servizio.absolute_url()).json() self.assertEqual(res["canale_digitale_link"], page.absolute_url()) + res = self.api_session_anon.get(servizio.absolute_url()).json() + self.assertEqual(res["canale_digitale_link"], page.absolute_url() + "/login") + def test_canale_digitale_link_deserialized_as_plone_internal_url(self): page = api.content.create( container=self.portal, type="Document", title="Document"