Skip to content

Commit

Permalink
Merge pull request #48 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Dec 11, 2024
2 parents 37a3b64 + aebbb76 commit 66d87f8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 19 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
=========

6.1 - (2024-12-10)
---------------------------
* Fix: large query on context navigation when on layout or add new item.
We return no results when we have the `Additional files` variation set
since it has potential to have a very large number of items.
[ichim-david - refs #280463]
* Feature: Add `Language` querystring field in order to be able to filter by language in Search block
[avoinea - refs #281503]

6.0 - (2024-12-05)
---------------------------
* Change: Fix plone.app.vocabularies.Users to work with Creators and Contributors Field
Expand Down
9 changes: 9 additions & 0 deletions eea/volto/policy/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
post_handler=".setuphandlers.post_install"
/>

<genericsetup:registerProfile
name="multilingual"
title="eea.volto.policy"
directory="profiles/multilingual"
description="Installs the eea.volto.policy multilingual options."
provides="Products.GenericSetup.interfaces.EXTENSION"
post_handler=".setuphandlers.post_install"
/>

<genericsetup:registerProfile
name="uninstall"
title="eea.volto.policy (uninstall)"
Expand Down
2 changes: 1 addition & 1 deletion eea/volto/policy/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>5.4</version>
<version>6.1</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="eea.volto.policy">
<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.Language">
<value key="title" i18n:translate="">Language</value>
<value key="description" i18n:translate="">The language of the content.</value>
<value key="enabled">True</value>
<value key="sortable">False</value>
<value key="operations">
<element>plone.app.querystring.operation.selection.any</element>
</value>
<value key="vocabulary">plone.app.vocabularies.SupportedContentLanguages</value>
<value key="group" i18n:domain="plone" i18n:translate="">Text</value>
</records>
</registry>
64 changes: 47 additions & 17 deletions eea/volto/policy/restapi/services/contextnavigation/get.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""EEA Context Navigation"""

from Acquisition import aq_inner
from zope.component import getUtility
from zope.component import adapter
from zope.globalrequest import getRequest
from zope.schema.interfaces import IFromUnicode
from zope.interface import implementer
from zope.interface import Interface
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFPlone.utils import normalizeString
from plone.app.layout.navigation.navtree import buildFolderTree
from plone.app.layout.navigation.root import getNavigationRoot
from plone.app.dexterity import _
from plone.restapi.services.contextnavigation import get as original_get
Expand All @@ -15,6 +19,7 @@
from plone.restapi.bbb import safe_hasattr
from plone import schema
from plone import api
from plone.memoize.instance import memoize


class IEEANavigationPortlet(original_get.INavigationPortlet):
Expand Down Expand Up @@ -87,11 +92,25 @@ def __init__(self, context, data):
if depth == 0:
depth = 999

currentFolderOnly = data.currentFolderOnly

root = original_get.get_root(context, data.root_path)
if root is not None:
rootPath = "/".join(root.getPhysicalPath())
else:
rootPath = getNavigationRoot(context)
rootPath = getNavigationRoot(context) if not currentFolderOnly \
else "/".join(context.getPhysicalPath())

# avoid large queries on layout pages where context is site
if currentFolderOnly:
request = getRequest()
# don't query when we add a new page and we use report_navigation
is_site = ISiteRoot.providedBy(context)
if is_site or 'add?type' in request.get('HTTP_REFERER', '') and \
request.form.get('expand.contextnavigation.variation', '')\
== 'report_navigation':
self.query = {}
return

# EEA modification to always use the rootPath for query
self.query["path"] = {"query": rootPath, "depth": depth,
Expand All @@ -106,7 +125,15 @@ def __init__(self, context, data):
self.query["path"]["navtree_start"] = depth


original_get.QueryBuilder = EEAContextNavigationQueryBuilder
class EEANavtreeStrategy(original_get.NavtreeStrategy):
"""Custom NavtreeStrategy for context navigation"""

def decoratorFactory(self, node):
"""Decorate the navigation tree"""
new_node = super().decoratorFactory(node)
if getattr(new_node["item"], "side_nav_title", False):
new_node["side_nav_title"] = new_node["item"].side_nav_title
return new_node


class EEANavigationPortletRenderer(original_get.NavigationPortletRenderer):
Expand Down Expand Up @@ -180,6 +207,24 @@ def title(self):
# handle bug where empty title is set to undefined from Volto
return name if name != "undefined" else self.data.title

@memoize
def getNavTree(self, _marker=None):
""" Get the navigation tree """

if _marker is None:
_marker = []
context = aq_inner(self.context)
queryBuilder = EEAContextNavigationQueryBuilder(context, self.data)
query_result = queryBuilder()
if not query_result:
return {"children": []}
strategy = EEANavtreeStrategy(context, self.data)

tree = buildFolderTree(
context, obj=context, query=query_result, strategy=strategy
)
return tree

def recurse(self, children, level, bottomLevel):
"""Recurse through the navigation tree"""
res = []
Expand Down Expand Up @@ -289,18 +334,3 @@ def reply(self):
return navigation(expand=True, prefix="expand.contextnavigation.")[
"contextnavigation"
]


class EEANavtreeStrategy(original_get.NavtreeStrategy):
"""Custom NavtreeStrategy for context navigation"""

def decoratorFactory(self, node):
"""Decorate the navigation tree"""
new_node = super().decoratorFactory(node)
if getattr(new_node["item"], "side_nav_title", False):
new_node["side_nav_title"] = new_node["item"].side_nav_title
return new_node


# Monkey patch the original NavtreeStrategy
original_get.NavtreeStrategy = EEANavtreeStrategy
1 change: 1 addition & 0 deletions eea/volto/policy/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def getNonInstallableProfiles(self):
""" Hide uninstall profile from site-creation and quickinstaller.
"""
return [
'eea.volto.policy:multilingual',
'eea.volto.policy:uninstall',
]

Expand Down
12 changes: 12 additions & 0 deletions eea/volto/policy/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@

</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="5.4"
destination="6.1"
profile="eea.volto.policy:default">

<genericsetup:upgradeDepends
title="Import all steps from eea.volto.policy multilingual profile"
import_profile="eea.volto.policy:multilingual"
/>

</genericsetup:upgradeSteps>

</configure>
2 changes: 1 addition & 1 deletion eea/volto/policy/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0
6.1

0 comments on commit 66d87f8

Please sign in to comment.