diff roundup/backends/rdbms_common.py @ 7936:a9b136565838

feat: issue1525113 - notation to filter by logged-in user At long last (almost 18 years) this patch lands. It allows sharing of queries that want to use the currently logged in user (i.e. I or me). By replacing an id number for the user by '@current_user' in the query you can share the query for "my issues" where 'my' is the logged in user not the person who created the query. Updated the templates to use this. Updated upgrading.py for directions on using it. RDBMS and anydbm both work. Also expressions using it (e.g. not @current_user) work and are tested. Test code done. I am not sure what the change to templating.py does. I am following the original patch and have built a test case to hit the if clause. But the rest of the test doesn't actualy provide the props I need. If I knew what that code was supposed to do there I would create a real test.
author John Rouillard <rouilj@ieee.org>
date Mon, 06 May 2024 00:49:43 -0400
parents 8b31893f5930
children 741ea8a86012
line wrap: on
line diff
--- a/roundup/backends/rdbms_common.py	Sun May 05 20:57:11 2024 -0400
+++ b/roundup/backends/rdbms_common.py	Mon May 06 00:49:43 2024 -0400
@@ -2313,6 +2313,10 @@
             raise TypeError('No key property set for class %s' %
                             self.classname)
 
+        # special notation for looking up the current database user
+        if keyvalue == '@current_user' and self.classname == 'user':
+            keyvalue = self.db.user.get(self.db.getuid(), self.key)
+
         # use the arg to handle any odd database type conversion (hello,
         # sqlite)
         sql = "select id from _%s where _%s=%s and __retired__=%s" % (
@@ -2566,6 +2570,10 @@
         """
         pln = proptree.parent.uniqname
         prp = proptree.name
+
+        if proptree.classname == 'user' and '@current_user' in v:
+            cu = self.db.getuid()
+            v = [x if x != "@current_user" else cu for x in v]
         try:
             opcodes = [int(x) for x in v]
             if min(opcodes) >= -1:
@@ -2843,6 +2851,9 @@
                                 where.append(w)
                                 args += arg
                         else:
+                            if v == '@current_user' and \
+                               propclass.classname == 'user':
+                                v = self.db.getuid()
                             if v in ('-1', None):
                                 v = None
                                 where.append('_%s._%s is NULL' % (pln, k))

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