Skip to content

Commit 0b7acad

Browse files
committed
Make permission filter functions configurable
For debugging and performance measurements it makes sense to allow turning permission filter functions off.
1 parent 167164a commit 0b7acad

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

roundup/configuration.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,17 @@ def str2value(self, value):
14621462
("rdbms", (
14631463
(DatabaseBackend, 'backend', NODEFAULT,
14641464
"Database backend."),
1465+
(BooleanOption, "debug_filter", "no",
1466+
"Filter debugging: Permissions can define additional filter\n"
1467+
"functions that are used when checking permissions on results\n"
1468+
"returned by the database. This is done to improve\n"
1469+
"performance since the filtering is done in the database\n"
1470+
"backend, not in python (at least for the SQL backends). The\n"
1471+
"user is responsible for making the filter return the same\n"
1472+
"set of results as the check function for a permission. So it\n"
1473+
"makes sense to aid in debugging (and performance\n"
1474+
"measurements) to allow turning off the usage of filter\n"
1475+
"functions using only the check functions."),
14651476
(Option, 'name', 'roundup',
14661477
"Name of the database to use. For Postgresql, this can\n"
14671478
"be database.schema to use a specific schema within\n"
@@ -1545,8 +1556,8 @@ def str2value(self, value):
15451556
"Set the database cursor for filter queries to serverside\n"
15461557
"cursor, this avoids caching large amounts of data in the\n"
15471558
"client. This option only applies for the postgresql backend."),
1548-
), "Settings in this section (except for backend) are used\n"
1549-
" by RDBMS backends only.",
1559+
), "Most settings in this section (except for backend and debug_filter)\n"
1560+
"are used by RDBMS backends only.",
15501561
),
15511562
("sessiondb", (
15521563
(SessiondbBackendOption, "backend", "",

roundup/hyperdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,11 +1820,12 @@ def filter_with_permissions(self, search_matches, filterspec, sort=[],
18201820
if check(permission, userid, cn, only_no_check = True):
18211821
allowed = item_ids
18221822
else:
1823+
debug = self.db.config.RDBMS_DEBUG_FILTER
18231824
# Note that is_filterable returns True if no permissions are
18241825
# found. This makes it fail early (with an empty allowed list)
18251826
# instead of running through all ids with an empty
18261827
# permission list.
1827-
if sec.is_filterable(permission, userid, cn):
1828+
if not debug and sec.is_filterable(permission, userid, cn):
18281829
new_ids = set(item_ids)
18291830
confirmed = set()
18301831
for perm in sec.filter_iter(permission, userid, cn):

test/db_test_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,22 @@ def filter(db, userid, klass):
30333033
# User may see own and public queries
30343034
self.assertEqual(r, ['5', '6', '4', '3', '2', '1'])
30353035

3036+
def testFilteringWithPermissionFilterFunctionOff(self):
3037+
view_query = self.setupQuery()
3038+
3039+
def filter(db, userid, klass):
3040+
return [dict(filterspec = dict(private_for=['-1', userid]))]
3041+
perm = self.db.security.addPermission
3042+
p = perm(name='View', klass='query', check=view_query, filter=filter)
3043+
self.db.security.addPermissionToRole("User", p)
3044+
# Turn filtering off
3045+
self.db.config.RDBMS_DEBUG_FILTER = True
3046+
filt = self.db.query.filter_with_permissions
3047+
3048+
r = filt(None, {}, sort=[('+', 'name')])
3049+
# User may see own and public queries
3050+
self.assertEqual(r, ['5', '6', '4', '3', '2', '1'])
3051+
30363052
# XXX add sorting tests for other types
30373053

30383054
# nuke and re-create db for restore

0 commit comments

Comments
 (0)