Skip to content

Commit

Permalink
Reindex AT content on PATCH
Browse files Browse the repository at this point in the history
Fixes #531
  • Loading branch information
buchi committed Jun 24, 2018
1 parent c92af77 commit 8deb37c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -12,6 +12,10 @@ Bugfixes:
- Make sure DX DefaultFieldDeserializer validates field values.
[lgraf]

- Reindex AT content on PATCH.
Fixes `issue 531 <https://github.com/plone/plone.restapi/issues/531>`_.
[buchi]


2.1.0 (2018-06-23)
------------------
Expand All @@ -24,6 +28,8 @@ New Features:
- Include translated role title in `@roles` GET.
[lgraf]



2.0.1 (2018-06-22)
------------------

Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/deserializer/atcontent.py
Expand Up @@ -67,6 +67,7 @@ def __call__(self, validate_all=False, data=None):
notify(ObjectInitializedEvent(obj))
obj.at_post_create_script()
else:
obj.reindexObject()
notify(ObjectEditedEvent(obj))
obj.at_post_edit_script()

Expand Down
34 changes: 34 additions & 0 deletions src/plone/restapi/tests/test_content_patch.py
Expand Up @@ -8,6 +8,7 @@
from plone.app.testing import TEST_USER_PASSWORD
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.restapi.testing import PLONE_RESTAPI_AT_FUNCTIONAL_TESTING
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

import requests
Expand Down Expand Up @@ -162,3 +163,36 @@ def test_patch_image_with_the_contents_of_the_get_preserves_image(self):
self.assertTrue(response.json()['image'])
self.assertIn('content-type', response.json()['image'])
self.assertIn('download', response.json()['image'])


class TestATContentPatch(unittest.TestCase):

layer = PLONE_RESTAPI_AT_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer['app']
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
login(self.portal, TEST_USER_NAME)
self.portal.portal_repository._versionable_content_types = []
self.portal.invokeFactory(
'Document',
id='doc1',
title='My Document',
description='Some Description'
)
self.portal.doc1.unmarkCreationFlag()
transaction.commit()

def test_patch_reindexes_document(self):
requests.patch(
self.portal.doc1.absolute_url(),
headers={'Accept': 'application/json'},
auth=(TEST_USER_NAME, TEST_USER_PASSWORD),
json={
"description": "Foo Bar",
},
)
transaction.begin()
brain = self.portal.portal_catalog(UID=self.portal.doc1.UID())[0]
self.assertEqual(brain.Description, 'Foo Bar')

0 comments on commit 8deb37c

Please sign in to comment.