Skip to content

Commit

Permalink
Skip next/previous info for old versions if it can't be obtained (#1651)
Browse files Browse the repository at this point in the history
* Skip next/previous info for old versions if it can't be obtained

* changelog

* make it fully backwards compatible
  • Loading branch information
davisagli committed Jun 1, 2023
1 parent bfb3cd3 commit 053a266
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/1651.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix content serializer with an old version of an item that was renamed. @davisagli
13 changes: 9 additions & 4 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ def __call__(self, version=None, include_items=True):
}

# Insert next/prev information
nextprevious = NextPrevious(obj)
result.update(
{"previous_item": nextprevious.previous, "next_item": nextprevious.next}
)
try:
nextprevious = NextPrevious(obj)
result.update(
{"previous_item": nextprevious.previous, "next_item": nextprevious.next}
)
except ValueError:
# If we're serializing an old version that was renamed or moved,
# then its id might not be found inside the current object's container.
result.update({"previous_item": {}, "next_item": {}})

# Insert working copy information
if WorkingCopyInfo is not None:
Expand Down
9 changes: 9 additions & 0 deletions src/plone/restapi/tests/test_services_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def test_previous_version(self):
response = self.api_session.get(url)
self.assertEqual(response.json()["title"], "My Document")

def test_previous_version_of_renamed_item(self):
api.content.move(source=self.doc, id="renamed-doc")
transaction.commit()

url = self.doc.absolute_url() + "/@history/0"
response = self.api_session.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["id"], "doc_with_history")

def test_no_sharing(self):
url = self.doc.absolute_url() + "/@history/0"
response = self.api_session.get(url)
Expand Down

0 comments on commit 053a266

Please sign in to comment.