Skip to content

Commit

Permalink
Allow substring matches when filtering aliases in the URL Management …
Browse files Browse the repository at this point in the history
…control panel (#4031)

* Allow substring matches when filtering aliases in the URL Management control panel

* Add a marker to help use this from plone.restapi

* changelog
  • Loading branch information
davisagli authored Oct 17, 2024
1 parent abd111b commit 4d49209
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Products/CMFPlone/controlpanel/browser/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def view_url(self):


class RedirectionSet:
# Marker so that plone.restapi can detect if this is
# a version that supports the start and end parameters
supports_date_range_filtering = True

def __init__(self, query="", created="", manual="", start="", end=""):
self.storage = getUtility(IRedirectionStorage)

Expand All @@ -172,14 +176,16 @@ def __init__(self, query="", created="", manual="", start="", end=""):
self.portal_path_len = len(self.portal_path)

# noinspection PyProtectedMember
if query:
if query and query.startswith("/"):
# with query path /Plone/news:
# min_k is /Plone/news and
# max_k is /Plone/newt
# Apparently that is the way to minize the keys we ask.
min_k = "{:s}/{:s}".format(self.portal_path, query.strip("/"))
max_k = min_k[:-1] + chr(ord(min_k[-1]) + 1)
self.data = self.storage._paths.keys(min=min_k, max=max_k, excludemax=True)
elif query:
self.data = [path for path in self.storage._paths.keys() if query in path]
else:
self.data = self.storage._paths.keys()
if manual:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def test_redirection_controlpanel_filtering(self):
# this should return one and not two (we need excludemax=True)
redirects = RedirectionSet(query="/foo1/777")
self.assertEqual(len(redirects), 1)
# query without an initial slash matches any substring
redirects = RedirectionSet(query="999")
self.assertEqual(len(redirects), 2)

request = self.layer["request"].clone()
request.form["q"] = "/foo"
Expand Down
1 change: 1 addition & 0 deletions news/4031.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
URL Management control panel: Find substring matches when querying aliases. @davisagli

0 comments on commit 4d49209

Please sign in to comment.