Skip to content

Commit

Permalink
fix: isort force_single_line
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Nov 17, 2023
2 parents 038a832 + 25fac48 commit 997a040
Show file tree
Hide file tree
Showing 38 changed files with 300 additions and 158 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/isort.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
name: Isort
on: [push]
name: Run isort
on:
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: isort/isort-action@master
with:
configuration: --profile black
- uses: actions/checkout@v3
- uses: isort/isort-action@v1
1 change: 1 addition & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[settings]
profile=black
force_single_line = true
23 changes: 22 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
Changelog
=========

5.2.5 (unreleased)
5.3.1 (unreleased)
------------------
- Add upgrade step and setuphandler to fix robots.txt
original rules adding 'Allow: /*?expand*'
[lucabel]

- Nothing changed yet.


5.3.0 (2023-10-25)
------------------

- Fix: the 'fix-link' view has a bug that corrupts links by replacing
the current external URL with a URL that is always relative to the
site, even when requesting replacement with a link from a different
website.
[lucabel].

- plone.app.redirector.FourOhFourView.search_for_similar patch to enable conditionally
the search for similar
[folix-01]

- Set search/querystring-search limit patch only for anonymous users.
Auth users can need to perform an higher query (in contents view for example).
[cekk]

- Re-apply context UID filter in querystringsearch service (as it is in plone.restapi).
[cekk]

5.2.4 (2023-09-26)
------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="redturtle.volto",
version="5.2.5.dev0",
version="5.3.1.dev0",
description="Helper package to setup a RedTurtle's Plone site ready to work with Volto.",
long_description=long_description,
# Get more from https://pypi.org/classifiers/
Expand Down
3 changes: 2 additions & 1 deletion src/redturtle/volto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from plone.restapi.serializer import utils
from Products.ZCatalog.Catalog import Catalog
from zope.i18nmessageid import MessageFactory
from ZTUtils.Lazy import LazyCat, LazyMap
from ZTUtils.Lazy import LazyCat
from ZTUtils.Lazy import LazyMap

from redturtle.volto.catalogplan import Catalog_sorted_search_indexes

Expand Down
6 changes: 2 additions & 4 deletions src/redturtle/volto/browser/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.registry.browser.controlpanel import (
ControlPanelFormWrapper,
RegistryEditForm,
)
from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper
from plone.app.registry.browser.controlpanel import RegistryEditForm

from redturtle.volto import _
from redturtle.volto.interfaces import IRedTurtleVoltoSettings
Expand Down
13 changes: 12 additions & 1 deletion src/redturtle/volto/browser/fix_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import logging
import re
from urllib.parse import urlparse
from urllib.parse import urlunparse

from Acquisition import aq_base
from plone import api
Expand Down Expand Up @@ -67,6 +69,7 @@ def __call__(self):
# set the new value anyway because some values could not be transformed,
# but they now have the right url anyway.
setattr(item, name, res["new_value"])
item.reindexObject()
i += 1
logger.info("### END ###")
logger.info("### {} items fixed ###".format(len(fixed_objects)))
Expand All @@ -93,6 +96,10 @@ def check_pattern(self, value):
return True

def replace_pattern(self, value, is_link=False):
# obtain data to make link sub evaluation
current_host = urlparse(self.request.URL).netloc
destination_host = urlparse(self.portal_url).netloc

for url in self.request.form.get("to_replace", "").split():
match = re.search(r"(?<={}).*".format(url), value)
if match:
Expand All @@ -105,7 +112,11 @@ def replace_pattern(self, value, is_link=False):
return value
if obj:
if is_link:
return "${portal_url}/resolveuid/" + obj.UID()
if current_host != destination_host:
new_url = urlparse(value)._replace(netloc=destination_host)
return urlunparse(new_url)
else:
return "${portal_url}/resolveuid/" + obj.UID()
else:
return obj.UID()
return value
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def search_for_similar(*args, **kwargs):

if (
os.environ.get("REDTURTLE_VOLTO_ENABLE_SEARCH_FOR_SIMILAR", default=None)
and original_obj
and original_obj # noqa
):
return original_obj._old_search_for_similar()

Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/volto/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>4200</version>
<version>4300</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
<dependency>profile-plone.app.caching:with-caching-proxy</dependency>
Expand Down
10 changes: 7 additions & 3 deletions src/redturtle/volto/restapi/deserializer/dxfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
)
from plone.restapi.interfaces import IFieldDeserializer
from Products.CMFPlone.utils import safe_unicode
from pytz import timezone, utc
from pytz import timezone
from pytz import utc
from z3c.form.interfaces import IDataManager
from zope.component import adapter, getMultiAdapter, queryMultiAdapter
from zope.component import adapter
from zope.component import getMultiAdapter
from zope.component import queryMultiAdapter
from zope.interface import implementer
from zope.schema.interfaces import IDatetime, ITextLine
from zope.schema.interfaces import IDatetime
from zope.schema.interfaces import ITextLine

from redturtle.volto.interfaces import IRedturtleVoltoLayer

Expand Down
3 changes: 2 additions & 1 deletion src/redturtle/volto/restapi/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
)
from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
from zope.component import adapter
from zope.interface import Interface, implementer
from zope.interface import Interface
from zope.interface import implementer

from redturtle.volto.interfaces import IRedturtleVoltoLayer

Expand Down
9 changes: 4 additions & 5 deletions src/redturtle/volto/restapi/serializer/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

from plone import api
from plone.restapi.behaviors import IBlocks
from plone.restapi.interfaces import (
IBlockFieldSerializationTransformer,
ISerializeToJsonSummary,
)
from plone.restapi.interfaces import IBlockFieldSerializationTransformer
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.blocks import uid_to_url
from Products.CMFPlone.interfaces import IPloneSiteRoot
from zope.component import adapter, getMultiAdapter
from zope.component import adapter
from zope.component import getMultiAdapter
from zope.globalrequest import getRequest
from zope.interface import implementer

Expand Down
3 changes: 2 additions & 1 deletion src/redturtle/volto/restapi/serializer/dxfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from plone.restapi.serializer.utils import uid_to_url
from zope.component import adapter
from zope.interface import implementer
from zope.schema.interfaces import IDatetime, ITextLine
from zope.schema.interfaces import IDatetime
from zope.schema.interfaces import ITextLine

from redturtle.volto.interfaces import IRedturtleVoltoLayer

Expand Down
3 changes: 2 additions & 1 deletion src/redturtle/volto/restapi/serializer/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
)
from plone.restapi.serializer.utils import uid_to_url
from zope.component import adapter
from zope.interface import Interface, implementer
from zope.interface import Interface
from zope.interface import implementer

from redturtle.volto.interfaces import IRedturtleVoltoLayer

Expand Down
9 changes: 4 additions & 5 deletions src/redturtle/volto/restapi/services/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from plone.restapi.controlpanels import RegistryConfigletPanel
from zope.component import adapter
from zope.interface import Interface, implementer
from zope.interface import Interface
from zope.interface import implementer

from redturtle.volto.interfaces import (
IRedTurtleVoltoSettings,
IRedTurtleVoltoSettingsControlpanel,
)
from redturtle.volto.interfaces import IRedTurtleVoltoSettings
from redturtle.volto.interfaces import IRedTurtleVoltoSettingsControlpanel


@adapter(Interface, Interface)
Expand Down
6 changes: 4 additions & 2 deletions src/redturtle/volto/restapi/services/navigation/get.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from plone.app.layout.navigation.navtree import NavtreeStrategyBase, buildFolderTree
from plone.app.layout.navigation.navtree import NavtreeStrategyBase
from plone.app.layout.navigation.navtree import buildFolderTree
from plone.dexterity.interfaces import IDexterityContainer
from plone.restapi.interfaces import IExpandableElement
from plone.restapi.services import Service
from zope.component import adapter
from zope.interface import Interface, implementer
from zope.interface import Interface
from zope.interface import implementer


@implementer(IExpandableElement)
Expand Down
36 changes: 21 additions & 15 deletions src/redturtle/volto/restapi/services/querystringsearch/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
from urllib import parse

from DateTime import DateTime
from plone import api
from plone.app.event.base import get_events
from plone.app.querystring import queryparser
from plone.restapi.batching import HypermediaBatch
from plone.restapi.bbb import IPloneSiteRoot
from plone.restapi.deserializer import json_body
from plone.restapi.exceptions import DeserializationError
from plone.restapi.interfaces import ISerializeToJson, ISerializeToJsonSummary
from plone.restapi.interfaces import ISerializeToJson
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.services import Service
from plone.restapi.services.querystringsearch.get import SUPPORT_NOT_UUID_QUERIES
from plone.restapi.services.querystringsearch.get import (
QuerystringSearch as BaseQuerystringSearch,
)
Expand Down Expand Up @@ -69,14 +73,12 @@ def __call__(self):
limit=limit,
)

# PATCH: we disable this query to boost performances on big sites
# Exclude "self" content item from the results when ZCatalog supports NOT UUID
# queries and it is called on a content object.
# if not IPloneSiteRoot.providedBy(self.context) and SUPPORT_NOT_UUID_QUERIES:
# querybuilder_parameters.update(
# dict(custom_query={"UID": {"not": self.context.UID()}})
# )
# END OF PATCH
if not IPloneSiteRoot.providedBy(self.context) and SUPPORT_NOT_UUID_QUERIES:
querybuilder_parameters.update(
dict(custom_query={"UID": {"not": self.context.UID()}})
)

try:
results = querybuilder(**querybuilder_parameters)
Expand All @@ -95,21 +97,25 @@ def get_limit(self, data):
"""
If limit is <= 0 or higher than MAX_LIMIT, set it to MAX_LIMIT
"""
is_anon = api.user.is_anonymous()
default_value = is_anon and MAX_LIMIT or max(1000, MAX_LIMIT)
if "limit" not in data:
return default_value
try:
limit = int(data.get("limit", MAX_LIMIT))
except ValueError:
raise BadRequest("Invalid limit")
limit = int(data.get("limit", default_value))
except ValueError as exc:
raise BadRequest("Invalid limit") from exc

if "limit" in data and limit <= 0:
if limit <= 0:
del data["limit"]
limit = MAX_LIMIT
if limit > MAX_LIMIT:
limit = default_value
if limit > default_value:
logger.warning(
'[wrong query] limit is too high: "{}". Set to default ({}).'.format(
data["query"], MAX_LIMIT
data["query"], default_value
)
)
limit = MAX_LIMIT
limit = default_value
return limit

def is_event_search(self, query):
Expand Down
42 changes: 25 additions & 17 deletions src/redturtle/volto/restapi/services/search/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# when the term is in 'Subject' and high when it is in 'Title'.
# print the id and the normalized rank
try:
from Products.AdvancedQuery import And, Eq, In, Or, RankByQueries_Sum
from Products.AdvancedQuery import And
from Products.AdvancedQuery import Eq
from Products.AdvancedQuery import In
from Products.AdvancedQuery import Or
from Products.AdvancedQuery import RankByQueries_Sum

HAS_ADVANCEDQUERY = True
except ImportError:
Expand Down Expand Up @@ -120,26 +124,30 @@ def search(self, query=None):
return super(SearchHandler, self).search(query)

def _parse_query(self, query):
"""
set a max limit for anonymous calls
"""
query = super()._parse_query(query)
for idx in ["sort_limit", "b_size"]:
if idx not in query:
continue
value = query.get(idx, MAX_LIMIT)
if value <= 0:
logger.warning(
'[wrong query] {} is wrong: "{}". Set to default ({}).'.format(
idx, query, MAX_LIMIT
if api.user.is_anonymous():
for idx in ["sort_limit", "b_size"]:
if idx not in query:
continue
value = query.get(idx, MAX_LIMIT)
if value <= 0:
logger.warning(
'[wrong query] {} is wrong: "{}". Set to default ({}).'.format(
idx, query, MAX_LIMIT
)
)
)
query[idx] = MAX_LIMIT
query[idx] = MAX_LIMIT

if value > MAX_LIMIT:
logger.warning(
'[wrong query] {} is too high: "{}". Set to default ({}).'.format(
idx, query, MAX_LIMIT
if value > MAX_LIMIT:
logger.warning(
'[wrong query] {} is too high: "{}". Set to default ({}).'.format(
idx, query, MAX_LIMIT
)
)
)
query[idx] = MAX_LIMIT
query[idx] = MAX_LIMIT
return query


Expand Down
Loading

0 comments on commit 997a040

Please sign in to comment.