Skip to content

Commit 0d78cf9

Browse files
committed
Make properties method return only properties the user can search.
See: https://sourceforge.net/p/roundup/mailman/roundup-devel/thread/20170405002844.2004B80690%40vm71.cs.umb.edu/#msg35769250 [Roundup-devel] Bug in context/properties, lists properties user can't search. The HTMLClass::properties() method returns a list of all properties. This is used when creating sort on/group by filters on index pages. However somewhere in the code, a user needs search permission on the property in order for it to be used for grouping or sorting. This means the user can choose to sort/group an index page by a property that they have no search permission for. As a result the sort/group is ignored. This is confusing. I have changed the properties method to only return properties the user has View/Search permissions on. I also added a new cansearch argument set by default to True. If set to False, all properties regardless of Search permission are returned. Doc updated to include the new default operation and mention the use of cansearch argument.
1 parent c709acd commit 0d78cf9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ Fixed:
413413
will not add the arg to the url. In the example above @queryname
414414
will only be in the url if dispname is set in the request.
415415
(John Rouillard)
416+
- The HTMLClass::properties() method produced a list of properties
417+
that the user could not search. As a result these properties can not
418+
be used for sorting or grouping index pages. This patch eliminates
419+
the confusion that results from this mismatch by verifying that all
420+
properties returned are searchable. (John Rouillard)
416421

417422
2016-01-11: 1.5.1
418423

doc/customizing.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,8 @@ There are several methods available on these wrapper objects:
23542354
Method Description
23552355
=========== =============================================================
23562356
properties return a `hyperdb property wrapper`_ for all of this class's
2357-
properties.
2357+
properties that are searchable by the user. You can use
2358+
the argument cansearch=False to get all properties.
23582359
list lists all of the active (not retired) items in the class.
23592360
csv return the items of this class as a chunk of CSV text.
23602361
propnames lists the names of the properties of this class.

roundup/cgi/templating.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,20 @@ def getItem(self, itemid, num_re=num_re):
596596

597597
return HTMLItem(self._client, self.classname, itemid)
598598

599-
def properties(self, sort=1):
600-
""" Return HTMLProperty for all of this class' properties.
599+
def properties(self, sort=1, cansearch=True):
600+
""" Return HTMLProperty for allowed class' properties.
601+
602+
To return all properties call it with cansearch=False
603+
and it will return properties the user is unable to
604+
search.
601605
"""
602606
l = []
607+
canSearch=self._db.security.hasSearchPermission
608+
userid=self._client.userid
603609
for name, prop in self._props.items():
610+
if cansearch and \
611+
not canSearch(userid, self._classname, name):
612+
continue
604613
for klass, htmlklass in propclasses:
605614
if isinstance(prop, klass):
606615
value = prop.get_default_value()

0 commit comments

Comments
 (0)