Skip to content

Commit f9bcf5d

Browse files
committed
When computing batch check class-permissions first
1 parent 657dfb0 commit f9bcf5d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

roundup/cgi/templating.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,9 +3453,12 @@ def batch(self, permission='View'):
34533453
matches = None
34543454

34553455
# filter for visibility
3456-
allowed = [itemid for itemid in klass.filter(matches, filterspec,
3457-
sort, group)
3458-
if check(permission, userid, self.classname, itemid=itemid)]
3456+
item_ids = klass.filter(matches, filterspec, sort, group)
3457+
if check(permission, userid, self.classname, only_no_check = True):
3458+
allowed = item_ids
3459+
else:
3460+
allowed = [id for id in item_ids
3461+
if check(permission, userid, self.classname, itemid=id)]
34593462

34603463
# return the batch object, using IDs only
34613464
return Batch(self.client, allowed, self.pagesize, self.startwith,

roundup/security.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def getPermission(self, permission, classname=None, properties=None,
310310
classname))
311311

312312
def hasPermission(self, permission, userid, classname=None,
313-
property=None, itemid=None):
313+
property=None, itemid=None, only_no_check=False):
314314
'''Look through all the Roles, and hence Permissions, and
315315
see if "permission" exists given the constraints of
316316
classname, property, itemid, and props_only.
@@ -345,7 +345,10 @@ def hasPermission(self, permission, userid, classname=None,
345345
# Note that checks with a check method are typically a lot more
346346
# expensive than the ones without. So we check the ones without
347347
# a check method first
348-
for has_check in False, True:
348+
checklist = (False, True)
349+
if only_no_check:
350+
checklist = (False,)
351+
for has_check in checklist:
349352
for rolename in self.db.user.get_roles(userid):
350353
if not rolename or (rolename not in self.role):
351354
continue

0 commit comments

Comments
 (0)