Skip to content

Commit

Permalink
Fix types expander in root for 5.2 (for non-DX Plone Site Root) (#1669)
Browse files Browse the repository at this point in the history
* Fix types expander in root for 5.2 when a DX Plone Site Root is not present

* Changelog

* Remove modified Python version in Makefile

* Update news/1669.bugfix

---------

Co-authored-by: David Glick <david@glicksoftware.com>
  • Loading branch information
sneridagh and davisagli committed Jul 14, 2023
1 parent 1ec84f2 commit ea0f2c7
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/1669.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix types expander in root for Plone 5.2 (for non-Dexterity Plone Site Root) @sneridagh
6 changes: 3 additions & 3 deletions plone-5.2.x.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[buildout]
extends =
https://dist.plone.org/release/5.2.9/versions.cfg
https://dist.plone.org/release/5.2.12/versions.cfg
base.cfg

[versions]
black = 21.7b0

# Use the new plone.rest alpha
plone.rest = 2.0.0a3
# Use the newest plone.rest
plone.rest = 3.0.0
2 changes: 1 addition & 1 deletion requirements-5.2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r https://dist.plone.org/release/5.2.9/requirements.txt
-r https://dist.plone.org/release/5.2.12/requirements.txt
zpretty
5 changes: 5 additions & 0 deletions src/plone/restapi/services/types/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@
name="types"
/>

<adapter
factory=".get.TypesInfoRoot"
name="types"
/>

</configure>
7 changes: 7 additions & 0 deletions src/plone/restapi/services/types/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from plone.restapi.types.utils import get_info_for_fieldset
from plone.restapi.types.utils import get_info_for_type
from Products.CMFCore.interfaces import IFolderish
from Products.CMFPlone.interfaces import IPloneSiteRoot
from Products.CMFCore.utils import getToolByName
from zExceptions import Unauthorized
from zope.component import adapter
Expand Down Expand Up @@ -85,6 +86,12 @@ def __call__(self, expand=False):
return result


@implementer(IExpandableElement)
@adapter(IPloneSiteRoot, Interface)
class TypesInfoRoot(TypesInfo):
pass


@implementer(IPublishTraverse)
class TypesGet(Service):
def __init__(self, context, request):
Expand Down
86 changes: 86 additions & 0 deletions src/plone/restapi/tests/test_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ def test_types_is_expandable(self):
self.assertEqual(response.status_code, 200)
self.assertIn("types", list(response.json().get("@components")))

def test_types_is_expandable_in_root(self):
response = self.api_session.get("/")

self.assertEqual(response.status_code, 200)
self.assertIn("types", list(response.json().get("@components")))

def test_types_expanded(self):
response = self.api_session.get("/folder", params={"expand": "types"})

Expand Down Expand Up @@ -418,6 +424,86 @@ def test_types_expanded(self):
response.json().get("@components").get("types"),
)

def test_types_expanded_in_root(self):
response = self.api_session.get("/", params={"expand": "types"})

self.assertEqual(response.status_code, 200)

# XXX: Note: The @types endpoint currently doesn't conform to JSON-LD
# because it's directly returning a list, and does not have an @id
# property.

base_url = self.portal.absolute_url()

self.assertEqual(
[
{
"@id": "/".join((base_url, "@types/Collection")),
"addable": True,
"immediately_addable": True,
"title": "Collection",
"id": "Collection",
},
{
"@id": "/".join((base_url, "@types/DXTestDocument")),
"addable": True,
"immediately_addable": True,
"title": "DX Test Document",
"id": "DXTestDocument",
},
{
"@id": "/".join((base_url, "@types/Event")),
"addable": True,
"immediately_addable": True,
"title": "Event",
"id": "Event",
},
{
"@id": "/".join((base_url, "@types/File")),
"addable": True,
"immediately_addable": True,
"title": "File",
"id": "File",
},
{
"@id": "/".join((base_url, "@types/Folder")),
"addable": True,
"immediately_addable": True,
"title": "Folder",
"id": "Folder",
},
{
"@id": "/".join((base_url, "@types/Image")),
"addable": True,
"immediately_addable": True,
"title": "Image",
"id": "Image",
},
{
"@id": "/".join((base_url, "@types/Link")),
"addable": True,
"immediately_addable": True,
"title": "Link",
"id": "Link",
},
{
"@id": "/".join((base_url, "@types/News Item")),
"addable": True,
"immediately_addable": True,
"title": "News Item",
"id": "News Item",
},
{
"@id": "/".join((base_url, "@types/Document")),
"addable": True,
"immediately_addable": True,
"title": "Page",
"id": "Document",
},
],
response.json().get("@components").get("types"),
)


class TestTranslationExpansionFunctional(unittest.TestCase):
layer = PLONE_RESTAPI_DX_PAM_FUNCTIONAL_TESTING
Expand Down

0 comments on commit ea0f2c7

Please sign in to comment.