Skip to content

Commit

Permalink
update canale_digitale_link serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Bellenghi authored and Luca Bellenghi committed Sep 6, 2024
1 parent 023e8bc commit c75adbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/design/plone/contenttypes/restapi/serializers/dxfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion src/design/plone/contenttypes/tests/test_ct_servizio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit c75adbc

Please sign in to comment.