-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from eea/develop
Release
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope" xmlns:plone="http://namespaces.plone.org/plone"> | ||
|
||
<adapter | ||
factory=".navigation.Navigation" | ||
name="navigation" | ||
/> | ||
|
||
<plone:service | ||
method="GET" | ||
factory=".navigation.NavigationGet" | ||
for="zope.interface.Interface" | ||
permission="zope2.View" | ||
name="@navigation" | ||
layer="plone.restapi.interfaces.IPloneRestapiLayer" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" Navigation | ||
""" | ||
|
||
from urllib.parse import urlparse | ||
from plone.restapi.interfaces import IExpandableElement, IPloneRestapiLayer | ||
from plone.restapi.services.navigation.get import Navigation as BaseNavigation | ||
from plone.restapi.services.navigation.get import ( | ||
NavigationGet as BaseNavigationGet, | ||
) | ||
from Products.CMFCore.utils import getToolByName | ||
from zope.component import adapter | ||
from zope.interface import Interface, implementer | ||
|
||
|
||
@implementer(IExpandableElement) | ||
@adapter(Interface, IPloneRestapiLayer) | ||
class Navigation(BaseNavigation): | ||
"""Navigation adapter""" | ||
|
||
def customize_entry(self, entry, brain): | ||
"""append custom entries""" | ||
entry["brain"] = brain | ||
if hasattr(brain, "getRemoteUrl") and brain.getRemoteUrl: | ||
entry["path"] = urlparse(brain.getRemoteUrl).path | ||
pm = getToolByName(self.context, "portal_membership") | ||
if bool(pm.isAnonymousUser()): | ||
entry["@id"] = brain.getRemoteUrl | ||
|
||
return entry | ||
|
||
def render_item(self, item, path): | ||
"""build navtree from item helper""" | ||
sub = self.build_tree(item["path"], first_run=False) | ||
|
||
item.update({"items": sub}) | ||
|
||
if "path" in item: | ||
del item["path"] | ||
|
||
if "brain" in item: | ||
del item["brain"] | ||
|
||
return item | ||
|
||
|
||
class NavigationGet(BaseNavigationGet): | ||
"""Navigation get service""" | ||
|
||
def reply(self): | ||
"""reply""" | ||
navigation = Navigation(self.context, self.request) | ||
return navigation(expand=True)["navigation"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.1 | ||
3.2 |