plone.restapi/plone-only-login: Move expansion implementation of breadcrumbs and navigation
Thomas Buchberger <jenkins-z4DKO/[email protected]> Wed, 26 Jul 2017 07:45:56 -0700 (PDT)
| Newsgroups | gmane.comp.web.zope.plone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Repository: plone.restapi Branch: refs/heads/plone-only-login Date: 2017-07-25T15:51:21+02:00 Author: Thomas Buchberger (buchi) <t.buchberger-/8aE7x569Db/[email protected]> Commit: https://github.com/plone/plone.restapi/commit/d89934c1e720ae70b574a1df7520a56c2a49da71 Move expansion implementation of breadcrumbs and navigation to new endpoints Files changed: M docs/source/_json/collection.resp M docs/source/_json/content_get.resp M docs/source/_json/content_post.resp M docs/source/_json/document.resp M docs/source/_json/event.resp M docs/source/_json/expansion.resp M docs/source/_json/expansion_expanded.resp M docs/source/_json/expansion_expanded_full.resp M docs/source/_json/file.resp M docs/source/_json/folder.resp M docs/source/_json/image.resp M docs/source/_json/jwt_logged_in.resp M docs/source/_json/link.resp M docs/source/_json/newsitem.resp M docs/source/_json/siteroot.resp M src/plone/restapi/services/breadcrumbs/configure.zcml M src/plone/restapi/services/breadcrumbs/get.py M src/plone/restapi/services/components/configure.zcml M src/plone/restapi/services/configure.zcml M src/plone/restapi/services/navigation/configure.zcml M src/plone/restapi/services/navigation/get.py diff --git a/docs/source/_json/collection.resp b/docs/source/_json/collection.resp index 4927c64d..912d4895 100644 --- a/docs/source/_json/collection.resp +++ b/docs/source/_json/collection.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/collection/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/collection/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/collection/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/collection/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/collection/@navigation" } }, "@id": "http://localhost:55001/plone/collection", diff --git a/docs/source/_json/content_get.resp b/docs/source/_json/content_get.resp index a13516ef..84d1571b 100644 --- a/docs/source/_json/content_get.resp +++ b/docs/source/_json/content_get.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/folder/my-document/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/folder/my-document/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/folder/my-document/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/folder/my-document/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/folder/my-document/@navigation" } }, "@id": "http://localhost:55001/plone/folder/my-document", diff --git a/docs/source/_json/content_post.resp b/docs/source/_json/content_post.resp index 5e3acd2c..c627cff8 100644 --- a/docs/source/_json/content_post.resp +++ b/docs/source/_json/content_post.resp @@ -4,16 +4,14 @@ Location: http://localhost:55001/plone/folder/my-document { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/folder/my-document/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/folder/my-document/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/folder/my-document/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/folder/my-document/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/folder/my-document/@navigation" } }, "@id": "http://localhost:55001/plone/folder/my-document", diff --git a/docs/source/_json/document.resp b/docs/source/_json/document.resp index d9b64694..e385c01e 100644 --- a/docs/source/_json/document.resp +++ b/docs/source/_json/document.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/front-page/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/front-page/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/front-page/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/front-page/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/front-page/@navigation" } }, "@id": "http://localhost:55001/plone/front-page", diff --git a/docs/source/_json/event.resp b/docs/source/_json/event.resp index 42e2d492..be0da16c 100644 --- a/docs/source/_json/event.resp +++ b/docs/source/_json/event.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/event/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/event/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/event/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/event/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/event/@navigation" } }, "@id": "http://localhost:55001/plone/event", diff --git a/docs/source/_json/expansion.resp b/docs/source/_json/expansion.resp index d9b64694..e385c01e 100644 --- a/docs/source/_json/expansion.resp +++ b/docs/source/_json/expansion.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/front-page/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/front-page/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/front-page/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/front-page/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/front-page/@navigation" } }, "@id": "http://localhost:55001/plone/front-page", diff --git a/docs/source/_json/expansion_expanded.resp b/docs/source/_json/expansion_expanded.resp index 5a9b1f25..30b0ac27 100644 --- a/docs/source/_json/expansion_expanded.resp +++ b/docs/source/_json/expansion_expanded.resp @@ -3,19 +3,20 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": [ + "@workflow": { + "@id": "http://localhost:55001/plone/front-page/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/front-page/@breadcrumbs", + "items": [ { "title": "Welcome to Plone", "url": "http://localhost:55001/plone/front-page" } - ], - "navigation": { - "@id": "http://localhost:55001/plone/front-page/@components/navigation" - } + ] }, - "@workflow": { - "@id": "http://localhost:55001/plone/front-page/@workflow" + "navigation": { + "@id": "http://localhost:55001/plone/front-page/@navigation" } }, "@id": "http://localhost:55001/plone/front-page", diff --git a/docs/source/_json/expansion_expanded_full.resp b/docs/source/_json/expansion_expanded_full.resp index 7456da91..7dd04d52 100644 --- a/docs/source/_json/expansion_expanded_full.resp +++ b/docs/source/_json/expansion_expanded_full.resp @@ -3,24 +3,6 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": [ - { - "title": "Welcome to Plone", - "url": "http://localhost:55001/plone/front-page" - } - ], - "navigation": [ - { - "title": "Home", - "url": "http://localhost:55001/plone" - }, - { - "title": "Welcome to Plone", - "url": "http://localhost:55001/plone/front-page" - } - ] - }, "@workflow": { "history": [ { @@ -42,6 +24,28 @@ Content-Type: application/json "title": "Submit for publication" } ] + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/front-page/@breadcrumbs", + "items": [ + { + "title": "Welcome to Plone", + "url": "http://localhost:55001/plone/front-page" + } + ] + }, + "navigation": { + "@id": "http://localhost:55001/plone/front-page/@navigation", + "items": [ + { + "title": "Home", + "url": "http://localhost:55001/plone" + }, + { + "title": "Welcome to Plone", + "url": "http://localhost:55001/plone/front-page" + } + ] } }, "@id": "http://localhost:55001/plone/front-page", diff --git a/docs/source/_json/file.resp b/docs/source/_json/file.resp index c1374a34..cf619bea 100644 --- a/docs/source/_json/file.resp +++ b/docs/source/_json/file.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/file/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/file/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/file/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/file/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/file/@navigation" } }, "@id": "http://localhost:55001/plone/file", diff --git a/docs/source/_json/folder.resp b/docs/source/_json/folder.resp index e711350f..483f9491 100644 --- a/docs/source/_json/folder.resp +++ b/docs/source/_json/folder.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/folder/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/folder/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/folder/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/folder/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/folder/@navigation" } }, "@id": "http://localhost:55001/plone/folder", diff --git a/docs/source/_json/image.resp b/docs/source/_json/image.resp index b7396435..73b4a020 100644 --- a/docs/source/_json/image.resp +++ b/docs/source/_json/image.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/image/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/image/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/image/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/image/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/image/@navigation" } }, "@id": "http://localhost:55001/plone/image", diff --git a/docs/source/_json/jwt_logged_in.resp b/docs/source/_json/jwt_logged_in.resp index 8630e5fa..a5842fe6 100644 --- a/docs/source/_json/jwt_logged_in.resp +++ b/docs/source/_json/jwt_logged_in.resp @@ -3,13 +3,11 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/@components/navigation" - } + "breadcrumbs": { + "@id": "http://localhost:55001/plone/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/@navigation" } }, "@id": "http://localhost:55001/plone/", diff --git a/docs/source/_json/link.resp b/docs/source/_json/link.resp index 66aa8179..6152d001 100644 --- a/docs/source/_json/link.resp +++ b/docs/source/_json/link.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/link/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/link/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/link/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/link/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/link/@navigation" } }, "@id": "http://localhost:55001/plone/link", diff --git a/docs/source/_json/newsitem.resp b/docs/source/_json/newsitem.resp index 17f89f37..740c6619 100644 --- a/docs/source/_json/newsitem.resp +++ b/docs/source/_json/newsitem.resp @@ -3,16 +3,14 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/newsitem/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/newsitem/@components/navigation" - } - }, "@workflow": { "@id": "http://localhost:55001/plone/newsitem/@workflow" + }, + "breadcrumbs": { + "@id": "http://localhost:55001/plone/newsitem/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/newsitem/@navigation" } }, "@id": "http://localhost:55001/plone/newsitem", diff --git a/docs/source/_json/siteroot.resp b/docs/source/_json/siteroot.resp index b21bc3d4..fa5c4db4 100644 --- a/docs/source/_json/siteroot.resp +++ b/docs/source/_json/siteroot.resp @@ -3,13 +3,11 @@ Content-Type: application/json { "@components": { - "@components": { - "breadcrumbs": { - "@id": "http://localhost:55001/plone/@components/breadcrumbs" - }, - "navigation": { - "@id": "http://localhost:55001/plone/@components/navigation" - } + "breadcrumbs": { + "@id": "http://localhost:55001/plone/@breadcrumbs" + }, + "navigation": { + "@id": "http://localhost:55001/plone/@navigation" } }, "@id": "http://localhost:55001/plone", diff --git a/src/plone/restapi/services/breadcrumbs/configure.zcml b/src/plone/restapi/services/breadcrumbs/configure.zcml index 0c39c889..167d7168 100644 --- a/src/plone/restapi/services/breadcrumbs/configure.zcml +++ b/src/plone/restapi/services/breadcrumbs/configure.zcml @@ -2,6 +2,8 @@ xmlns="http://namespaces.zope.org/zope" xmlns:plone="http://namespaces.plone.org/plone"> + <adapter factory=".get.Breadcrumbs" name="breadcrumbs"/> + <plone:service method="GET" for="zope.interface.Interface" @@ -9,5 +11,5 @@ name="@breadcrumbs" permission="zope2.View" /> - + </configure> diff --git a/src/plone/restapi/services/breadcrumbs/get.py b/src/plone/restapi/services/breadcrumbs/get.py index 8bfbe701..c09c4c9d 100644 --- a/src/plone/restapi/services/breadcrumbs/get.py +++ b/src/plone/restapi/services/breadcrumbs/get.py @@ -1,22 +1,44 @@ # -*- coding: utf-8 -*- +from plone.restapi.interfaces import IExpandableElement from plone.restapi.services import Service +from zope.component import adapter from zope.component import getMultiAdapter +from zope.interface import Interface +from zope.interface import implementer -class BreadcrumbsGet(Service): +@implementer(IExpandableElement) +@adapter(Interface, Interface) +class Breadcrumbs(object): - def reply(self): - breadcrumbs_view = getMultiAdapter((self.context, self.request), - name="breadcrumbs_view") + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self, expand=False): result = { - '@id': '{}/@breadcrumbs'.format( - self.context.absolute_url() - ), - 'items': [] + 'breadcrumbs': { + '@id': '{}/@breadcrumbs'.format(self.context.absolute_url()), + }, } + if not expand: + return result + + breadcrumbs_view = getMultiAdapter((self.context, self.request), + name="breadcrumbs_view") + items = [] for crumb in breadcrumbs_view.breadcrumbs(): - result['items'].append({ + items.append({ 'title': crumb['Title'], 'url': crumb['absolute_url'] }) + + result['breadcrumbs']['items'] = items return result + + +class BreadcrumbsGet(Service): + + def reply(self): + breadcrumbs = Breadcrumbs(self.context, self.request) + return breadcrumbs(expand=True)['breadcrumbs'] diff --git a/src/plone/restapi/services/components/configure.zcml b/src/plone/restapi/services/components/configure.zcml index da8a360e..1ce44ab5 100644 --- a/src/plone/restapi/services/components/configure.zcml +++ b/src/plone/restapi/services/components/configure.zcml @@ -10,7 +10,4 @@ permission="zope2.View" /> - <adapter factory=".navigation.Navigation" name="navigation"/> - <adapter factory=".breadcrumbs.Breadcrumbs" name="breadcrumbs"/> - </configure> \ No newline at end of file diff --git a/src/plone/restapi/services/configure.zcml b/src/plone/restapi/services/configure.zcml index bc18fdfd..800995bb 100644 --- a/src/plone/restapi/services/configure.zcml +++ b/src/plone/restapi/services/configure.zcml @@ -2,13 +2,13 @@ xmlns="http://namespaces.zope.org/zope"> <include package=".auth" /> - <!--<include package=".breadcrumbs"/>--> + <include package=".breadcrumbs"/> <include package=".components"/> <include package=".content"/> <include package=".copymove"/> <include package=".discussion"/> <include package=".groups"/> - <!--<include package=".navigation"/>--> + <include package=".navigation"/> <include package=".history"/> <include package=".principals"/> <include package=".registry"/> diff --git a/src/plone/restapi/services/navigation/configure.zcml b/src/plone/restapi/services/navigation/configure.zcml index 05e200e4..090900cd 100644 --- a/src/plone/restapi/services/navigation/configure.zcml +++ b/src/plone/restapi/services/navigation/configure.zcml @@ -2,6 +2,8 @@ xmlns="http://namespaces.zope.org/zope" xmlns:plone="http://namespaces.plone.org/plone"> + <adapter factory=".get.Navigation" name="navigation"/> + <plone:service method="GET" for="zope.interface.Interface" diff --git a/src/plone/restapi/services/navigation/get.py b/src/plone/restapi/services/navigation/get.py index ab48b2e1..e59168c4 100644 --- a/src/plone/restapi/services/navigation/get.py +++ b/src/plone/restapi/services/navigation/get.py @@ -1,22 +1,43 @@ # -*- coding: utf-8 -*- +from plone.restapi.interfaces import IExpandableElement from plone.restapi.services import Service +from zope.component import adapter from zope.component import getMultiAdapter +from zope.interface import Interface +from zope.interface import implementer -class NavigationGet(Service): +@implementer(IExpandableElement) +@adapter(Interface, Interface) +class Navigation(object): - def reply(self): - tabs = getMultiAdapter((self.context, self.request), - name="portal_tabs_view") + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self, expand=False): result = { - '@id': '{}/@navigation'.format( - self.context.absolute_url() - ), - 'items': [] + 'navigation': { + '@id': '{}/@navigation'.format(self.context.absolute_url()), + }, } + if not expand: + return result + + tabs = getMultiAdapter((self.context, self.request), + name="portal_tabs_view") + items = [] for tab in tabs.topLevelTabs(): - result['items'].append({ + items.append({ 'title': tab.get('title', tab.get('name')), 'url': tab['url'] + '' }) + result['navigation']['items'] = items return result + + +class NavigationGet(Service): + + def reply(self): + navigation = Navigation(self.context, self.request) + return navigation(expand=True)['navigation'] ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot