Skip to content

Commit

Permalink
Merge 8271e5e into 3b2c9e9
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Apr 17, 2017
2 parents 3b2c9e9 + 8271e5e commit 9439a9a
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog

New Features:

- Add navigation and breadcrumbs as top-level services. Deprecate navigation
and breadcrumbs as components.
[timo]

- Add support for setting/modifying 'layout' on DX and AT content endpoints.
[jaroel]

Expand Down
12 changes: 12 additions & 0 deletions docs/source/breadcrumbs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Breadcrumbs
===========

Getting the breadcrumbs for the current page:

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

Example response:

.. literalinclude:: _json/breadcrumbs.resp
:language: http
5 changes: 5 additions & 0 deletions docs/source/components.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Components
==========

.. warning::
The @components endpoint is deprecated and will be removed in plone.restapi
1.0b1. :doc:`breadcrumbs` and :doc:`navigation` are now top-level endpoints.

How to get pages components (i.e. everything but the main content), like breadcrumbs, navigations, actions, etc.


Breadcrumbs
-----------

Expand Down
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Contents
types
users
components
breadcrumbs
navigation
serialization
searching
vocabularies
Expand Down
12 changes: 12 additions & 0 deletions docs/source/navigation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Navigation
==========

Getting the top navigation items:

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

Example response:

.. literalinclude:: _json/navigation.resp
:language: http
Empty file.
13 changes: 13 additions & 0 deletions src/plone/restapi/services/breadcrumbs/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone">

<plone:service
method="GET"
for="zope.interface.Interface"
factory=".get.BreadcrumbsGet"
name="@breadcrumbs"
permission="zope2.View"
/>

</configure>
17 changes: 17 additions & 0 deletions src/plone/restapi/services/breadcrumbs/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from plone.restapi.services import Service
from zope.component import getMultiAdapter


class BreadcrumbsGet(Service):

def reply(self):
breadcrumbs_view = getMultiAdapter((self.context, self.request),
name="breadcrumbs_view")
result = []
for crumb in breadcrumbs_view.breadcrumbs():
result.append({
'title': crumb['Title'],
'url': crumb['absolute_url']
})
return result
2 changes: 2 additions & 0 deletions src/plone/restapi/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
xmlns="http://namespaces.zope.org/zope">

<include package=".auth" />
<include package=".breadcrumbs"/>
<include package=".components"/>
<include package=".content"/>
<include package=".copymove"/>
<include package=".groups"/>
<include package=".navigation"/>
<include package=".principals"/>
<include package=".registry"/>
<include package=".search"/>
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions src/plone/restapi/services/navigation/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone">

<plone:service
method="GET"
for="zope.interface.Interface"
factory=".get.NavigationGet"
name="@navigation"
permission="zope2.View"
/>

</configure>
17 changes: 17 additions & 0 deletions src/plone/restapi/services/navigation/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from plone.restapi.services import Service
from zope.component import getMultiAdapter


class NavigationGet(Service):

def reply(self):
tabs = getMultiAdapter((self.context, self.request),
name="portal_tabs_view")
result = []
for tab in tabs.topLevelTabs():
result.append({
'title': tab.get('title', tab.get('name')),
'url': tab['url'] + ''
})
return result
51 changes: 51 additions & 0 deletions src/plone/restapi/tests/test_services_breadcrumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
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.dexterity.utils import createContentInContainer
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession

import transaction
import unittest


class TestServicesBreadcrumbs(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer['app']
self.portal = self.layer['portal']
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ['Manager'])

self.api_session = RelativeSession(self.portal_url)
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

self.folder = createContentInContainer(
self.portal, u'Folder',
id=u'folder',
title=u'Some Folder')
createContentInContainer(
self.folder, u'Document',
id=u'doc1',
title=u'A document')
transaction.commit()

def test_breadcrumbs(self):
response = self.api_session.get('/folder/doc1/@breadcrumbs')

self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json(),
[{
u'url': u'http://localhost:55001/plone/folder',
u'title': u'Some Folder'
}, {
u'url': u'http://localhost:55001/plone/folder/doc1',
u'title': u'A document'
}]
)
54 changes: 54 additions & 0 deletions src/plone/restapi/tests/test_services_navigation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
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.dexterity.utils import createContentInContainer
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession

import transaction
import unittest


class TestServicesNavigation(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer['app']
self.portal = self.layer['portal']
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ['Manager'])

self.api_session = RelativeSession(self.portal_url)
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

self.folder = createContentInContainer(
self.portal, u'Folder',
id=u'folder',
title=u'Some Folder')
createContentInContainer(
self.folder, u'Document',
id=u'doc1',
title=u'A document')
transaction.commit()

def test_navigation(self):
response = self.api_session.get('/folder/@navigation')

self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json(),
[
{
u'title': u'Home',
u'url': u'http://localhost:55001/plone'
},
{
u'title': u'Some Folder',
u'url': u'http://localhost:55001/plone/folder'
}
]
)

0 comments on commit 9439a9a

Please sign in to comment.