Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The member-search form is now protected #133

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/125.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The member-search logic has been moved from the page template to the Python code
[ale-rt]
33 changes: 29 additions & 4 deletions plone/app/users/browser/membersearch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from plone.autoform.form import AutoExtensibleForm
from plone.base import PloneMessageFactory as _
from plone.memoize.view import memoize
from plone.supermodel import model
from Products.CMFCore.permissions import ListPortalMembers
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from z3c.form import button
from z3c.form import form
Expand Down Expand Up @@ -97,6 +100,32 @@ class MemberSearchForm(AutoExtensibleForm, form.Form):

submitted = False

@property
@memoize
def listing_allowed(self):
"""
Check if the user has the necessary "List Portal Members" permissions
to view the list of search results.
"""
pm = getToolByName(self.context, "portal_membership")
return pm.checkPermission(ListPortalMembers, self.context)

@property
def results(self):
"""
Retrieve, merge, and sort the list of results based on search criteria.

This is based on the methods previously defined in the
Products.PlonePAS.browser.search module.
"""
# First of all check if we have the proper permissions
if not self.listing_allowed:
return []

view = self.context.restrictedTraverse("@@pas_search")
criteria = extractCriteriaFromRequest(self.request.form.copy())
return view.searchUsers(sort_by="fullname", **criteria)

@button.buttonAndHandler(_("label_search", default="Search"), name="search")
def handleApply(self, action):
request = self.request
Expand All @@ -108,7 +137,3 @@ def handleApply(self, action):

if request.get("form.buttons.search", None):
self.submitted = True

view = self.context.restrictedTraverse("@@pas_search")
criteria = extractCriteriaFromRequest(self.request.form.copy())
self.results = view.searchUsers(sort_by="fullname", **criteria)
4 changes: 2 additions & 2 deletions plone/app/users/browser/membersearch_form.pt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<tal:block condition="view/submitted">
<article id="content"
tal:define="
listing_allowed python: checkPermission('List portal members', here);
results python:listing_allowed and view.results;
listing_allowed python: view.listing_allowed;
results python: view.results;
Batch python:modules['Products.CMFPlone'].Batch;
DateTime python:modules['DateTime'].DateTime;
b_size python:12;
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"plone.base",
"plone.formwidget.namedfile >= 1.0.3",
"plone.i18n",
"plone.memoize",
"plone.namedfile",
"plone.protect",
"plone.registry",
Expand Down
Loading