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

added function get_allow_discussion_value #1674

Merged
merged 23 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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/1674.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the function `get_allow_discussion_value(context, request)`. It returns `True` if discussion is allowed, or `False` if not, based on the enabled status of the `conversation_view` adapter. @Akshat2Jain
12 changes: 9 additions & 3 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
WorkingCopyInfo = None


def get_allow_discussion_value(context, request, result):
# This test is to handle the plone.app.discussion not being installed situation
if "allow_discussion" in result:
result["allow_discussion"] = getMultiAdapter(
(context, request), name="conversation_view"
).enabled()


@implementer(ISerializeToJson)
@adapter(IDexterityContent, Interface)
class SerializeToJson:
Expand Down Expand Up @@ -125,9 +133,7 @@ def __call__(self, version=None, include_items=True):
if target_url:
result["targetUrl"] = target_url

result["allow_discussion"] = getMultiAdapter(
(self.context, self.request), name="conversation_view"
).enabled()
get_allow_discussion_value(self.context, self.request, result)

return result

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/serializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from zope.interface import Interface
from zope.schema import getFields
from zope.security.interfaces import IPermission
from plone.restapi.serializer.dxcontent import get_allow_discussion_value

import json

Expand Down Expand Up @@ -121,6 +122,8 @@ def __call__(self, version=None):
for brain in batch
]

get_allow_discussion_value(self.context, self.request, result)

return result

def check_permission(self, permission_name, obj):
Expand Down
11 changes: 0 additions & 11 deletions src/plone/restapi/tests/test_dxcontent_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,17 +576,6 @@ def test_allow_discussion_fti_disallows_allows_global_enabled_but_instance_allow
self.assertIn("allow_discussion", obj)
self.assertEqual(True, obj["allow_discussion"])

def test_allow_discussion_global_enabled_but_instance_has_no_discussion_behavior(
self,
): # noqa
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
settings.globally_enabled = True

obj = self.serialize()
self.assertIn("allow_discussion", obj)
self.assertEqual(False, obj["allow_discussion"])


class TestDXContentPrimaryFieldTargetUrl(unittest.TestCase):
layer = PLONE_RESTAPI_DX_INTEGRATION_TESTING
Expand Down