Skip to content

Commit

Permalink
Show expired content when GET on a folderish object, include a way to…
Browse files Browse the repository at this point in the history
… display it on @search via the show_inactive parameter
  • Loading branch information
sneridagh committed Jul 27, 2017
1 parent 0271e70 commit 5bd97c7
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ New Features:
- Add skipped tests from @breadcrumbs and @navigation now that the expansion is in place
[sneridagh]

- Show expired content when GET on a folderish object, include a way to display
it on @search via the show_inactive parameter
[sneridagh]


1.0a20 (2017-07-24)
-------------------
Expand Down
6 changes: 6 additions & 0 deletions docs/source/content.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,9 @@ A response 400 BadRequest with a message 'Content ordering is not supported by t

.. http:example:: curl httpie python-requests
:request: _json/content_reorder.req


Expired content
---------------

When retrieving the content items they will include all the content in the folder/site, including the expired content that might contain.
11 changes: 11 additions & 0 deletions docs/source/searching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ You do so by specifying the ``fullobjects`` parameter:
.. warning::

Be aware that this might induce performance issues when retrieving a lot of resources. Normally the search just serializes catalog brains, but with full objects we wake up all the returned objects.


Expired content
---------------

This endpoint will not return any expired content unless you use and set the ``show_inactive`` query to true.

.. code-block:: http
GET /plone/@search?show_inactive=1 HTTP/1.1
Accept: application/json
1 change: 1 addition & 0 deletions src/plone/restapi/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ZCatalogCompatibleQueryAdapter(object):
'sort_limit': int,
'b_start': int,
'b_size': int,
'show_inactive': bool
}

def __init__(self, context, request):
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/serializer/atcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class SerializeFolderToJson(SerializeToJson):
def _build_query(self):
path = '/'.join(self.context.getPhysicalPath())
query = {'path': {'depth': 1, 'query': path},
'sort_on': 'getObjPositionInParent'}
'sort_on': 'getObjPositionInParent',
'show_inactive': True}
return query

def __call__(self, version=None):
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class SerializeFolderToJson(SerializeToJson):
def _build_query(self):
path = '/'.join(self.context.getPhysicalPath())
query = {'path': {'depth': 1, 'query': path},
'sort_on': 'getObjPositionInParent'}
'sort_on': 'getObjPositionInParent',
'show_inactive': True}
return query

def __call__(self, version=None):
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/serializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __init__(self, context, request):
def _build_query(self):
path = '/'.join(self.context.getPhysicalPath())
query = {'path': {'depth': 1, 'query': path},
'sort_on': 'getObjPositionInParent'}
'sort_on': 'getObjPositionInParent',
'show_inactive': True}
return query

def __call__(self, version=None):
Expand Down
28 changes: 28 additions & 0 deletions src/plone/restapi/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,31 @@ def test_uuid_index_query(self):
[u'/plone/folder/doc'],
result_paths(response.json())
)

def test_search_expired_doc_not_showing(self):
self.portal['doc-outside-folder'].setExpirationDate(
DateTime('2017/01/01'))
wftool = getToolByName(self.portal, 'portal_workflow')
wftool.doActionFor(self.portal['doc-outside-folder'], 'submit')
wftool.doActionFor(self.portal['doc-outside-folder'], 'publish')
self.portal['doc-outside-folder'].reindexObject()
transaction.commit()

self.api_session.auth = ('', '')
response = self.api_session.get('/@search')
response = response.json()
self.assertEquals(len(response['items']), 0)

def test_search_expired_doc_showing_using_show_inactive(self):
self.portal['doc-outside-folder'].setExpirationDate(
DateTime('2017/01/01'))
wftool = getToolByName(self.portal, 'portal_workflow')
wftool.doActionFor(self.portal['doc-outside-folder'], 'submit')
wftool.doActionFor(self.portal['doc-outside-folder'], 'publish')
self.portal['doc-outside-folder'].reindexObject()
transaction.commit()

self.api_session.auth = ('', '')
response = self.api_session.get('/@search?show_inactive=1')
response = response.json()
self.assertEquals(len(response['items']), 1)
15 changes: 15 additions & 0 deletions src/plone/restapi/tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from DateTime import DateTime
from plone.app.testing import logout
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.textfield.value import RichTextValue
Expand Down Expand Up @@ -367,3 +368,17 @@ def test_serialize_to_json_collection(self):
],
self.serialize(self.portal.collection1).get('items')
)

def test_serialize_folder_returns_expired_items(self):
self.portal.doc1.setExpirationDate(DateTime('2017/01/01'))
wftool = getToolByName(self.portal, 'portal_workflow')
wftool.doActionFor(self.portal.doc1, 'submit')
wftool.doActionFor(self.portal.doc1, 'publish')
self.portal.doc1.reindexObject()
# We test it with published content for not to fiddle with permissions
# and users
logout()
self.assertEqual(
len(self.serialize(self.portal)['items']),
1
)
17 changes: 17 additions & 0 deletions src/plone/restapi/tests/test_services_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from plone.dexterity.utils import createContentInContainer
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName

import transaction
import unittest
Expand Down Expand Up @@ -55,3 +57,18 @@ def test_navigation(self):
]
}
)

def test_navigation_expired_items(self):
self.folder.setExpirationDate(DateTime('2017/01/01'))
wftool = getToolByName(self.portal, 'portal_workflow')
wftool.doActionFor(self.folder, 'submit')
wftool.doActionFor(self.folder, 'publish')
self.folder.reindexObject()
transaction.commit()

self.api_session.auth = ('', '')
response = self.api_session.get('/@navigation')
response = response.json()

self.assertEquals(len(response['items']), 1)
self.assertEquals(response['items'][0]['title'], 'Home')

0 comments on commit 5bd97c7

Please sign in to comment.