Skip to content

Commit

Permalink
Merge pull request #151 from plone/explicitacquisition
Browse files Browse the repository at this point in the history
Dont publish items that are acquired.
  • Loading branch information
mauritsvanrees authored Oct 10, 2023
2 parents 47e2ac8 + 054b023 commit 809346b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/explicitacquisition.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Make REST endpoints check for acquired items.
[jaroel]
4 changes: 4 additions & 0 deletions src/plone/rest/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
provides="zope.interface.Interface"
/>

<adapter
provides="plone.rest.interfaces.IShouldAllowAcquiredItemPublication"
factory=".explicitacquisition.rest_allowed" />

</configure>
8 changes: 8 additions & 0 deletions src/plone/rest/explicitacquisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from plone.rest.interfaces import IShouldAllowAcquiredItemPublication
from plone.rest.traverse import RESTWrapper
from zope.component import adapter


@adapter(RESTWrapper)
def rest_allowed(wrapper):
return IShouldAllowAcquiredItemPublication(wrapper.context)
8 changes: 8 additions & 0 deletions src/plone/rest/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ def process_simple_request():

def process_preflight_request():
"""Process a preflight request"""


try:
from Products.CMFCore.interfaces import IShouldAllowAcquiredItemPublication
except ImportError:

class IShouldAllowAcquiredItemPublication(Interface):
pass
57 changes: 57 additions & 0 deletions src/plone/rest/tests/test_explicitacquisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from base64 import b64encode
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.rest.testing import PLONE_REST_INTEGRATION_TESTING
from zExceptions import NotFound
from zope.event import notify
from ZPublisher.pubevents import PubAfterTraversal
from ZPublisher.pubevents import PubStart

import unittest


try:
from Products.CMFCore.interfaces import IShouldAllowAcquiredItemPublication
except ImportError:
IShouldAllowAcquiredItemPublication = None


@unittest.skipIf(
IShouldAllowAcquiredItemPublication is None,
"Older Plone versions don't have CMFCore>=3.2",
)
class TestExplicitAcquisition(unittest.TestCase):
layer = PLONE_REST_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer["portal"]
self.request = self.layer["request"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Document", id="foo")

def traverse(self, path="/plone", accept="application/json", method="GET"):
request = self.layer["request"]
request.environ["PATH_INFO"] = path
request.environ["PATH_TRANSLATED"] = path
request.environ["HTTP_ACCEPT"] = accept
request.environ["REQUEST_METHOD"] = method
auth = f"{SITE_OWNER_NAME}:{SITE_OWNER_PASSWORD}"
b64auth = b64encode(auth.encode("utf8"))
request._auth = "Basic %s" % b64auth.decode("utf8")
notify(PubStart(request))
return request.traverse(path)

def test_portal_root(self):
self.traverse("/plone")
notify(PubAfterTraversal(self.request))

def test_portal_foo(self):
self.traverse("/plone/foo")
notify(PubAfterTraversal(self.request))

def test_portal_foo_acquired(self):
self.traverse("/plone/foo/foo")
with self.assertRaises(NotFound):
notify(PubAfterTraversal(self.request))

0 comments on commit 809346b

Please sign in to comment.