Skip to content

Commit

Permalink
Merge pull request #42 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Nov 14, 2024
2 parents cbe6eb3 + fc28d3a commit 88e9676
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

5.6 - (2024-11-11)
---------------------------
* Feature: customized actions endpoint to allow passing of props to the
actions endpoint
[ichim-david - refs #271001]
* Feature: customized breadcrumbs endpoint to add portal_type info to the
items served by the breadcrumbs endpoint
[ichim-david - refs #271001]

5.5 - (2024-10-18)
---------------------------
* Change: Fix broken brain error at the upgrade svg step - refs #276995
Expand Down
62 changes: 62 additions & 0 deletions eea/volto/policy/browser/breadcrumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Breadcrumbs"""

# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_inner
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.navigation.root import getNavigationRoot
from Products.CMFPlone import utils
from Products.CMFPlone.browser.interfaces import INavigationBreadcrumbs
from Products.CMFPlone.browser.navigation import get_view_url
from Products.CMFPlone.defaultpage import check_default_page_via_view
from Products.CMFPlone.interfaces import IHideFromBreadcrumbs
from Products.Five import BrowserView
from zope.component import getMultiAdapter
from zope.interface import implementer


@implementer(INavigationBreadcrumbs)
class PhysicalNavigationBreadcrumbs(BrowserView):
"""EEA Physical Navigation Breadcrumbs"""

def breadcrumbs(self):
"""breadcrumbs"""
context = aq_inner(self.context)
request = self.request
container = utils.parent(context)
_name, item_url = get_view_url(context)
# EEA add portal_type info to breadcrumbs
last_crumb = {
"absolute_url": item_url,
"Title": utils.pretty_title_or_id(context, context),
"portal_type": context.portal_type,
"nav_title": getattr(aq_base(context), "nav_title", ""),
}

if container is None:
return (last_crumb,)

# Replicate Products.CMFPlone.browser.navigation.
# RootPhysicalNavigationBreadcrumbs.breadcrumbs()
# cause it is not registered during tests
if INavigationRoot.providedBy(context):
return ()

view = getMultiAdapter((container, request),
name="eea_breadcrumbs_view")
base = tuple(view.breadcrumbs())

# Some things want to be hidden from the breadcrumbs
if IHideFromBreadcrumbs.providedBy(context):
return base

rootPath = getNavigationRoot(context)
itemPath = "/".join(context.getPhysicalPath())

# don't show default pages in breadcrumbs or pages above the navigation
# root
if not check_default_page_via_view(
context, request
) and not rootPath.startswith(itemPath):
base += (last_crumb,)
return base
9 changes: 9 additions & 0 deletions eea/volto/policy/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@
permission="cmf.ManagePortal"
/>

<browser:page
name="eea_breadcrumbs_view"
for="*"
class=".breadcrumbs.PhysicalNavigationBreadcrumbs"
allowed_attributes="breadcrumbs"
permission="zope.Public"
layer="eea.volto.policy.interfaces.IEeaVoltoPolicyLayer"
/>

</configure>
1 change: 1 addition & 0 deletions eea/volto/policy/restapi/services/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""" EEA Actions overrides """
13 changes: 13 additions & 0 deletions eea/volto/policy/restapi/services/actions/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:cache="http://namespaces.zope.org/cache"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
>

<adapter
factory=".get.EEAActions"
name="actions"
/>

</configure>
54 changes: 54 additions & 0 deletions eea/volto/policy/restapi/services/actions/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Breadcrumbs"""

from zope.component import getMultiAdapter
from zope.component import adapter
from zope.i18n import translate
from zope.interface import implementer
from zope.interface import Interface
from plone.restapi.interfaces import IExpandableElement, IPloneRestapiLayer
from plone.restapi.services.actions.get import Actions


@implementer(IExpandableElement)
@adapter(Interface, IPloneRestapiLayer)
class EEAActions(Actions):
"""EEA Actions"""

def __call__(self, expand=False):
""" """
result = {"actions": {"@id":
f"{self.context.absolute_url()}/@actions"}}
if not expand:
return result

context_state = getMultiAdapter(
(self.context, self.request), name="plone_context_state"
)

categories = self.request.form.get("categories", self.all_categories)
filtered_action_props = {
"category",
"link_target",
"available",
"visible",
"allowed",
"modal",
}
data = {}
for category in categories:
category_action_data = []
actions = context_state.actions(category=category)
for action in actions:
# EEA allow actions props to be served by the endpoint except
# for the ones listed in filtered_action_props
action_data = {
key: translate(value, context=self.request)
if key == "title"
else value
for key, value in action.items()
if key not in filtered_action_props
}

category_action_data.append(action_data)
data[category] = category_action_data
return {"actions": data}
1 change: 1 addition & 0 deletions eea/volto/policy/restapi/services/breadcrumbs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""" Breadcrumbs """
13 changes: 13 additions & 0 deletions eea/volto/policy/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:cache="http://namespaces.zope.org/cache"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
>

<adapter
factory=".get.EEABreadcrumbs"
name="breadcrumbs"
/>

</configure>
45 changes: 45 additions & 0 deletions eea/volto/policy/restapi/services/breadcrumbs/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Breadcrumbs"""

from zope.component import getMultiAdapter
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
from plone.restapi.interfaces import IExpandableElement, IPloneRestapiLayer
from plone.restapi.services.breadcrumbs.get import Breadcrumbs


@implementer(IExpandableElement)
@adapter(Interface, IPloneRestapiLayer)
class EEABreadcrumbs(Breadcrumbs):
"""EEA Breadcrumbs"""

def __call__(self, expand=False):
""" """
result = {"breadcrumbs": {
"@id": f"{self.context.absolute_url()}/@breadcrumbs"}}
if not expand:
return result

portal_state = getMultiAdapter(
(self.context, self.request), name="plone_portal_state"
)
breadcrumbs_view = getMultiAdapter(
(self.context, self.request), name="eea_breadcrumbs_view"
)
items = []
# EEA add portal_type info to breadcrumbs
for crumb in breadcrumbs_view.breadcrumbs():
item = {
"title": crumb["Title"],
"portal_type": crumb.get("portal_type", ""),
"@id": crumb["absolute_url"],
}
if crumb.get("nav_title", False):
item.update({"title": crumb["nav_title"]})

items.append(item)

result["breadcrumbs"]["items"] = items
result["breadcrumbs"]["root"] = portal_state.navigation_root()\
.absolute_url()
return result
2 changes: 2 additions & 0 deletions eea/volto/policy/restapi/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
>
<include package=".contextnavigation" />
<include package=".breadcrumbs" />
<include package=".actions" />
</configure>
2 changes: 1 addition & 1 deletion eea/volto/policy/restapi/services/contextnavigation/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def recurse(self, children, level, bottomLevel):
@adapter(Interface, IPloneRestapiLayer)
class EEAContextNavigation:
"""Custom context navigation"""

def __init__(self, context, request):
self.context = context
self.request = request
Expand All @@ -255,7 +256,6 @@ def __call__(self, expand=False, prefix="expand.contextnavigation."):
}
if not expand:
return result
print("REQUEST FORM", self.request.form)
data = eea_extract_data(
IEEANavigationPortlet,
self.request.form,
Expand Down
2 changes: 1 addition & 1 deletion eea/volto/policy/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.5
5.6

0 comments on commit 88e9676

Please sign in to comment.