From c7b8e076deeb3c1f4b468521d0ecabfb0731483a Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Fri, 17 May 2024 12:17:37 +0200 Subject: [PATCH] Support for plone.app.discussion as core add-on (#1781) * No discussion related settings needed in a pa.iterate test. * for tests, explicitly pull in pa.discussion and apply it's profile. * add a note to the docs docs/source/endpoints/comments.md * conditional usage of plone.app.discussion (endpoint) * black, zpretty --------- Co-authored-by: Steve Piercy --- docs/source/endpoints/comments.md | 7 +++- news/1781.bugfix | 1 + setup.py | 1 + src/plone/restapi/serializer/configure.zcml | 6 ++-- src/plone/restapi/services/configure.zcml | 5 ++- src/plone/restapi/testing.py | 3 ++ src/plone/restapi/tests/statictime.py | 39 ++++++++++++--------- src/plone/restapi/tests/test_statictime.py | 4 --- 8 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 news/1781.bugfix diff --git a/docs/source/endpoints/comments.md b/docs/source/endpoints/comments.md index 8864da61ec..5be81aefe2 100644 --- a/docs/source/endpoints/comments.md +++ b/docs/source/endpoints/comments.md @@ -9,7 +9,12 @@ myst: # Comments -Plone offers to users a feature to post comments on any content object with `plone.app.discussion`. +```{versionchanged} Plone 6.1 +Discussion is disabled by default in Plone 6.1 and later. +To enable discussion, see the Plone 6.1 upgrade guide section {ref}`backend-upgrade-plone-v61-discussion-label`. +``` + +Discussion is a feature that allows your site visitors to comment on web pages for any content object. Commenting can be enabled globally for specific content types and for single content objects. diff --git a/news/1781.bugfix b/news/1781.bugfix new file mode 100644 index 0000000000..c7a5197bd7 --- /dev/null +++ b/news/1781.bugfix @@ -0,0 +1 @@ +Make plone.app.discussion an optional dependency (core add-on) [@jensens] \ No newline at end of file diff --git a/setup.py b/setup.py index 4863cdf89b..7e041a3ff0 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ def read(filename): "plone.app.caching", "plone.app.contenttypes[test]", "plone.app.iterate", + "plone.app.discussion[test]", "plone.app.testing", "plone.app.upgrade", "plone.api", diff --git a/src/plone/restapi/serializer/configure.zcml b/src/plone/restapi/serializer/configure.zcml index 614f3d4152..c1117121ae 100644 --- a/src/plone/restapi/serializer/configure.zcml +++ b/src/plone/restapi/serializer/configure.zcml @@ -107,8 +107,10 @@ - - + + + + diff --git a/src/plone/restapi/services/configure.zcml b/src/plone/restapi/services/configure.zcml index ed31ccf121..1f56801bd1 100644 --- a/src/plone/restapi/services/configure.zcml +++ b/src/plone/restapi/services/configure.zcml @@ -18,7 +18,10 @@ - + diff --git a/src/plone/restapi/testing.py b/src/plone/restapi/testing.py index 7ed7c0358d..adc4d184b3 100644 --- a/src/plone/restapi/testing.py +++ b/src/plone/restapi/testing.py @@ -135,6 +135,9 @@ def setUpPloneSite(self, portal): set_supported_languages(portal) + if portal.portal_setup.profileExists("plone.app.discussion:default"): + applyProfile(portal, "plone.app.discussion:default") + applyProfile(portal, "plone.restapi:default") applyProfile(portal, "plone.restapi:testing") add_catalog_indexes(portal, DX_TYPES_INDEXES) diff --git a/src/plone/restapi/tests/statictime.py b/src/plone/restapi/tests/statictime.py index 6357c19666..3f138b1b83 100644 --- a/src/plone/restapi/tests/statictime.py +++ b/src/plone/restapi/tests/statictime.py @@ -1,7 +1,6 @@ from datetime import datetime from datetime import timezone from DateTime import DateTime -from plone.app.discussion.comment import Comment from plone.app.layout.viewlets.content import ContentHistoryViewlet from plone.dexterity.content import DexterityContent from plone.locking.lockable import TTWLockable @@ -9,6 +8,11 @@ from Products.CMFCore.WorkflowTool import _marker from Products.CMFCore.WorkflowTool import WorkflowTool +try: + from plone.app.discussion.comment import Comment +except ImportError: + Comment = None + _originals = { "WorkflowTool.getInfoFor": WorkflowTool.getInfoFor, @@ -106,19 +110,21 @@ def start(self): DexterityContent.modification_date = property( static_modification_date_getter_factory(self.static_modified), nop_setter ) - - # Patch the lightweight p.a.discussion 'Comment' type. Its dates are - # Python datetimes, unlike DX Content types which use zope DateTimes. - Comment.creation_date = property( - static_creation_date_getter_factory(self.static_created, type_=datetime), - nop_setter, - ) - Comment.modification_date = property( - static_modification_date_getter_factory( - self.static_modified, type_=datetime - ), - nop_setter, - ) + if Comment is not None: + # Patch the lightweight p.a.discussion 'Comment' type. Its dates are + # Python datetimes, unlike DX Content types which use zope DateTimes. + Comment.creation_date = property( + static_creation_date_getter_factory( + self.static_created, type_=datetime + ), + nop_setter, + ) + Comment.modification_date = property( + static_modification_date_getter_factory( + self.static_modified, type_=datetime + ), + nop_setter, + ) WorkflowTool.getInfoFor = static_get_info_for_factory(self.static_modified) @@ -138,8 +144,9 @@ def stop(self): ] WorkflowTool.getInfoFor = _originals["WorkflowTool.getInfoFor"] - Comment.modification_date = None - Comment.creation_date = None + if Comment is not None: + Comment.modification_date = None + Comment.creation_date = None WorkingCopyInfo.created = _originals["WorkingCopyInfo.created"] diff --git a/src/plone/restapi/tests/test_statictime.py b/src/plone/restapi/tests/test_statictime.py index 38ba23a3d2..2cd654c19e 100644 --- a/src/plone/restapi/tests/test_statictime.py +++ b/src/plone/restapi/tests/test_statictime.py @@ -299,10 +299,6 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) - registry = getUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings, check=False) - settings.globally_enabled = True - transaction.commit() def create_document(self, id_):