diff test/db_test_base.py @ 8155:e9af08743759 permission-performance

Add check_factory For Permission objects where we're given a filter function but no check function, manufacture a check function.
author Ralf Schlatterbeck <rsc@runtux.com>
date Mon, 11 Nov 2024 14:32:25 +0100
parents 5a2b9435a04d
children 079958914ed7
line wrap: on
line diff
--- a/test/db_test_base.py	Mon Nov 11 11:25:55 2024 +0100
+++ b/test/db_test_base.py	Mon Nov 11 14:32:25 2024 +0100
@@ -3049,6 +3049,25 @@
         # User may see own and public queries
         self.assertEqual(r, ['5', '6', '4', '3', '2', '1'])
 
+    def testFilteringWithManufacturedCheckFunction(self):
+        # We define a permission with a filter function but no check
+        # function. The check function is manufactured automatically.
+        # Then we test the manufactured *check* function only by turning
+        # off the filter function.
+        view_query = self.setupQuery()
+
+        def filter(db, userid, klass):
+            return [dict(filterspec = dict(private_for=['-1', userid]))]
+        perm = self.db.security.addPermission
+        p = perm(name='View', klass='query', filter=filter)
+        self.db.security.addPermissionToRole("User", p)
+        # Turn filtering off
+        self.db.config.RDBMS_DEBUG_FILTER = True
+        filt = self.db.query.filter_with_permissions
+        r = filt(None, {}, sort=[('+', 'name')])
+        # User may see own and public queries
+        self.assertEqual(r, ['5', '6', '4', '3', '2', '1'])
+
 # XXX add sorting tests for other types
 
     # nuke and re-create db for restore

Roundup Issue Tracker: http://roundup-tracker.org/