diff --git a/CHANGES.rst b/CHANGES.rst index 23abec88..ff87feb0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,21 @@ Changelog ========= +6.2.19 (unreleased) +------------------- + +- Fix a bug introduced by changes in 6.2.16 + AttributeError: 'NoneType' object has no attribute 'absolute_url' + [mamico] + + +6.2.18 (2024-09-06) +------------------- + +- Refactor ServizioTextLineFieldSerializer adapter to check eventually a content type + [lucabel] + + 6.2.17 (2024-09-06) ------------------- @@ -12,7 +27,7 @@ Changelog ------------------- - On CT Servizio don't want to see 'unauthorized' for anonymous user when click on - "Accedi al servzio" but prefer to see an 'access' label, which can be obtained using + "Accedi al servizio" but prefer to see an 'access' label, which can be obtained using {url}/login. For this reason, we want to ensure that if the current user doesn't have permission to view the target of the 'access the service' button, a link with /login will be used instead. diff --git a/setup.py b/setup.py index 974f64ca..6451358a 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="design.plone.contenttypes", - version="6.2.17", + version="6.2.19.dev0", description="DesignItalia contenty types", long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/design/plone/contenttypes/restapi/serializers/dxfields.py b/src/design/plone/contenttypes/restapi/serializers/dxfields.py index 10080bb4..14af90dd 100644 --- a/src/design/plone/contenttypes/restapi/serializers/dxfields.py +++ b/src/design/plone/contenttypes/restapi/serializers/dxfields.py @@ -191,6 +191,7 @@ def get_item_children(item): class ServizioTextLineFieldSerializer(DefaultFieldSerializer): PERMISSION_TO_CHECK = "View" + CHECK_CONTENT_TYPE = None def __call__(self): value = self.get_value() @@ -206,9 +207,20 @@ def __call__(self): # we redirect him to the login page; /login has a more friendly message if api.user.is_anonymous(): target = uuidToObject(uid, unrestricted=True) - value = target.absolute_url() - if not api.user.has_permission(self.PERMISSION_TO_CHECK, obj=target): - value = f"{value}/login" + if target: + value = target.absolute_url() + if ( + self.CHECK_CONTENT_TYPE + and target.portal_type != self.CHECK_CONTENT_TYPE + ): + return json_compatible(value) + + if not api.user.has_permission( + self.PERMISSION_TO_CHECK, obj=target + ): + value = f"{value}/login" + else: + value = uuidToURL(uid) else: value = uuidToURL(uid) else: