Skip to content

Commit 0f54776

Browse files
committed
The member-search logic has been moved from the page template to the Python code
Refs. #125
1 parent 447c951 commit 0f54776

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

news/125.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The member-search logic has been moved from the page template to the Python code
2+
[ale-rt]

plone/app/users/browser/membersearch.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from plone.autoform.form import AutoExtensibleForm
22
from plone.base import PloneMessageFactory as _
3+
from plone.memoize.view import memoize
34
from plone.supermodel import model
5+
from Products.CMFCore.permissions import ListPortalMembers
6+
from Products.CMFCore.utils import getToolByName
47
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
58
from z3c.form import button
69
from z3c.form import form
@@ -97,6 +100,32 @@ class MemberSearchForm(AutoExtensibleForm, form.Form):
97100

98101
submitted = False
99102

103+
@property
104+
@memoize
105+
def listing_allowed(self):
106+
"""
107+
Check if the user has the necessary "List Portal Members" permissions
108+
to view the list of search results.
109+
"""
110+
pm = getToolByName(self.context, "portal_membership")
111+
return pm.checkPermission(ListPortalMembers, self.context)
112+
113+
@property
114+
def results(self):
115+
"""
116+
Retrieve, merge, and sort the list of results based on search criteria.
117+
118+
This is based on the methods previously defined in the
119+
Products.PlonePAS.browser.search module.
120+
"""
121+
# First of all check if we have the proper permissions
122+
if not self.listing_allowed:
123+
return []
124+
125+
view = self.context.restrictedTraverse("@@pas_search")
126+
criteria = extractCriteriaFromRequest(self.request.form.copy())
127+
return view.searchUsers(sort_by="fullname", **criteria)
128+
100129
@button.buttonAndHandler(_("label_search", default="Search"), name="search")
101130
def handleApply(self, action):
102131
request = self.request
@@ -108,7 +137,3 @@ def handleApply(self, action):
108137

109138
if request.get("form.buttons.search", None):
110139
self.submitted = True
111-
112-
view = self.context.restrictedTraverse("@@pas_search")
113-
criteria = extractCriteriaFromRequest(self.request.form.copy())
114-
self.results = view.searchUsers(sort_by="fullname", **criteria)

plone/app/users/browser/membersearch_form.pt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<tal:block condition="view/submitted">
2424
<article id="content"
2525
tal:define="
26-
listing_allowed python: checkPermission('List portal members', here);
27-
results python:listing_allowed and view.results;
26+
listing_allowed python: view.listing_allowed;
27+
results python: view.results;
2828
Batch python:modules['Products.CMFPlone'].Batch;
2929
DateTime python:modules['DateTime'].DateTime;
3030
b_size python:12;

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"plone.base",
7272
"plone.formwidget.namedfile >= 1.0.3",
7373
"plone.i18n",
74+
"plone.memoize",
7475
"plone.namedfile",
7576
"plone.protect",
7677
"plone.registry",

0 commit comments

Comments
 (0)