Skip to content

Commit 253a687

Browse files
committed
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.
1 parent 54ea9db commit 253a687

File tree

12 files changed

+162
-21
lines changed

12 files changed

+162
-21
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ Features:
203203
(e.g. description of what a priority or status means) without being
204204
able to select the property in the classhelper. Good for adding help
205205
for Link properties. (John Rouilllard)
206+
- issue1525113 - notation to filter by logged-in user. Use
207+
@current_user with properties that are a Link to the 'user' class to
208+
match the currently logged in user. Allows sharing of queries like
209+
"Issues I created" or "Issues I am assigned to" by removing the
210+
hard coded user id number and replacing it with the current user's
211+
id. Tracker templates updated to use it. (John Rouillard from a
212+
patch by Jon C. Thomason)
206213

207214
2023-07-13 2.3.0
208215

doc/upgrading.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,43 @@ The removed columns are: severity, versions, keywords, dependencies.
293293
It is also missing the ``solves`` field which is added to match the
294294
schema.
295295

296+
Use @current_user in Searches (optional)
297+
----------------------------------------
298+
299+
You can create queries like: "My issues" by searching the ``creator``
300+
property of issues for your id number. Similarly you can search for
301+
"Issues assigned to me" by searching on the ``assignedto`` property.
302+
303+
Queries in Roundup can be shared between users. However queries like
304+
these can be shared. However for any user but they will only find
305+
issues created by/assigned to the user who created the query.
306+
307+
This release allows you to search Links to the User class by
308+
specifying ``@current_user``. This token searches for the currently
309+
log in user. It makes searches like the above usable when shared.
310+
311+
This only works for properties that are a Link to the user
312+
class. E.G. creator, actor, assignedto. It does not yet work for
313+
MultiLink properties (like nosy).
314+
315+
As an example this can be deployed to the classic tracker's issue
316+
search template (issue.search.html), by replacing::
317+
318+
<option metal:fill-slot="extra_options" i18n:translate=""
319+
tal:attributes="value request/user/id">created by
320+
me</option>
321+
322+
with::
323+
324+
<option metal:fill-slot="extra_options" value="@current_user"
325+
tal:attributes="selected python:value == '@current_user'"
326+
i18n:translate="">created by me</option>
327+
328+
There are three places where ``value request/user/id`` is used in the
329+
classic template. Your template may have more.
330+
`Details can be found in issue1525113
331+
<https://issues.roundup-tracker.org/issue1525113>`_.
332+
296333
New PostgreSQL Settings (optional)
297334
----------------------------------
298335

roundup/backends/back_anydbm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,11 @@ def lookup(self, keyvalue):
15221522
if not self.key:
15231523
raise TypeError('No key property set for '
15241524
'class %s' % self.classname)
1525+
1526+
# special notation for looking up the current database user
1527+
if keyvalue == '@current_user' and self.classname == 'user':
1528+
keyvalue = self.db.user.get(self.db.getuid(), self.key)
1529+
15251530
cldb = self.db.getclassdb(self.classname)
15261531
try:
15271532
for nodeid in self.getnodeids(cldb):
@@ -1763,6 +1768,9 @@ def _filter(self, search_matches, filterspec, proptree,
17631768
if isinstance(propclass, hyperdb.Link):
17641769
if not isinstance(v, list):
17651770
v = [v]
1771+
if propclass.classname == 'user' and '@current_user' in v:
1772+
cu = self.db.getuid()
1773+
v = [x if x != "@current_user" else cu for x in v]
17661774
l.append((LINK, k, v))
17671775
elif isinstance(propclass, hyperdb.Multilink):
17681776
# If it's a reverse multilink, we've already

roundup/backends/rdbms_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,10 @@ def lookup(self, keyvalue):
23132313
raise TypeError('No key property set for class %s' %
23142314
self.classname)
23152315

2316+
# special notation for looking up the current database user
2317+
if keyvalue == '@current_user' and self.classname == 'user':
2318+
keyvalue = self.db.user.get(self.db.getuid(), self.key)
2319+
23162320
# use the arg to handle any odd database type conversion (hello,
23172321
# sqlite)
23182322
sql = "select id from _%s where _%s=%s and __retired__=%s" % (
@@ -2566,6 +2570,10 @@ def _filter_link_expression(self, proptree, v):
25662570
"""
25672571
pln = proptree.parent.uniqname
25682572
prp = proptree.name
2573+
2574+
if proptree.classname == 'user' and '@current_user' in v:
2575+
cu = self.db.getuid()
2576+
v = [x if x != "@current_user" else cu for x in v]
25692577
try:
25702578
opcodes = [int(x) for x in v]
25712579
if min(opcodes) >= -1:
@@ -2843,6 +2851,9 @@ def _filter_sql(self, search_matches, filterspec, srt=[], grp=[], retr=0,
28432851
where.append(w)
28442852
args += arg
28452853
else:
2854+
if v == '@current_user' and \
2855+
propclass.classname == 'user':
2856+
v = self.db.getuid()
28462857
if v in ('-1', None):
28472858
v = None
28482859
where.append('_%s._%s is NULL' % (pln, k))

roundup/cgi/templating.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,16 @@ def lookupIds(db, prop, ids, fail_ok=0, num_re=num_re, do_lookup=True):
564564
else:
565565
l.append(item)
566566
continue
567+
567568
# if fail_ok, ignore lookup error
568569
# otherwise entry must be existing object id rather than key value
569570
if fail_ok:
570571
l.append(entry)
572+
elif entry == '@current_user' and prop.classname == 'user':
573+
# as a special case, '@current_user' means the currently
574+
# logged-in user
575+
l.append(entry)
576+
571577
return l
572578

573579

share/roundup/templates/classic/html/issue.search.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@
8686
tal:condition="db/user/is_view_ok">
8787
<th i18n:translate="">Creator:</th>
8888
<td metal:use-macro="search_select">
89-
<option metal:fill-slot="extra_options" i18n:translate=""
90-
tal:attributes="value request/user/id">created by me</option>
89+
<option metal:fill-slot="extra_options" value="@current_user"
90+
tal:attributes="selected python:value == '@current_user'"
91+
i18n:translate="">created by me</option>
9192
</td>
9293
<td metal:use-macro="column_input"></td>
9394
<td metal:use-macro="sort_input"></td>
@@ -108,8 +109,9 @@
108109
tal:condition="db/user/is_view_ok">
109110
<th i18n:translate="">Actor:</th>
110111
<td metal:use-macro="search_select">
111-
<option metal:fill-slot="extra_options" i18n:translate=""
112-
tal:attributes="value request/user/id">done by me</option>
112+
<option metal:fill-slot="extra_options" value="@current_user"
113+
tal:attributes="selected python:value == '@current_user'"
114+
i18n:translate="">done by me</option>
113115
</td>
114116
<td metal:use-macro="column_input"></td>
115117
<td metal:use-macro="sort_input"></td>
@@ -153,7 +155,8 @@
153155
<th i18n:translate="">Assigned to:</th>
154156
<td metal:use-macro="search_select">
155157
<tal:block metal:fill-slot="extra_options">
156-
<option tal:attributes="value request/user/id"
158+
<option value="@current_user"
159+
tal:attributes="selected python:value == '@current_user'"
157160
i18n:translate="">assigned to me</option>
158161
<option value="-1" tal:attributes="selected python:value == '-1'"
159162
i18n:translate="">unassigned</option>

share/roundup/templates/devel/html/bug.search.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<th i18n:translate="">Creator:</th>
7474
<td metal:use-macro="search_input">
7575
<option metal:fill-slot="extra_options" i18n:translate=""
76-
tal:attributes="value request/user/id">created by me</option>
76+
value="@current_user"
77+
tal:attributes="selected python:value == '@current_user'">
78+
created by me</option>
7779
</td>
7880
<td metal:use-macro="column_input"></td>
7981
<td metal:use-macro="sort_input"></td>
@@ -94,7 +96,9 @@
9496
<th i18n:translate="">Last actor:</th>
9597
<td metal:use-macro="search_input">
9698
<option metal:fill-slot="extra_options" i18n:translate=""
97-
tal:attributes="value request/user/id">done by me</option>
99+
value="@current_user"
100+
tal:attributes="selected python:value == '@current_user'">
101+
done by me</option>
98102
</td>
99103
<td metal:use-macro="column_input"></td>
100104
<td metal:use-macro="sort_input"></td>
@@ -177,8 +181,9 @@
177181
<th i18n:translate="">Assigned to:</th>
178182
<td metal:use-macro="search_input">
179183
<tal:block metal:fill-slot="extra_options">
180-
<option tal:attributes="value request/user/id"
181-
i18n:translate="">assigned to me</option>
184+
<option value="@current_user"
185+
tal:attributes="selected python:value == '@current_user'"
186+
i18n:translate="">assigned to me</option>
182187
<option value="-1" tal:attributes="selected python:value == '-1'"
183188
i18n:translate="">unassigned</option>
184189
</tal:block>

share/roundup/templates/devel/html/task.search.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<th i18n:translate="">Creator:</th>
7474
<td metal:use-macro="search_input">
7575
<option metal:fill-slot="extra_options" i18n:translate=""
76-
tal:attributes="value request/user/id">created by me</option>
76+
value="@current_user"
77+
tal:attributes="selected python:value == '@current_user'">
78+
created by me</option>
7779
</td>
7880
<td metal:use-macro="column_input"></td>
7981
<td metal:use-macro="sort_input"></td>
@@ -94,7 +96,9 @@
9496
<th i18n:translate="">Last actor:</th>
9597
<td metal:use-macro="search_input">
9698
<option metal:fill-slot="extra_options" i18n:translate=""
97-
tal:attributes="value request/user/id">done by me</option>
99+
value="@current_user"
100+
tal:attributes="selected python:value == '@current_user'">
101+
done by me</option>
98102
</td>
99103
<td metal:use-macro="column_input"></td>
100104
<td metal:use-macro="sort_input"></td>
@@ -177,8 +181,9 @@
177181
<th i18n:translate="">Assigned to:</th>
178182
<td metal:use-macro="search_input">
179183
<tal:block metal:fill-slot="extra_options">
180-
<option tal:attributes="value request/user/id"
181-
i18n:translate="">assigned to me</option>
184+
<option value="@current_user"
185+
tal:attributes="selected python:value == '@current_user'"
186+
i18n:translate="">assigned to me</option>
182187
<option value="-1" tal:attributes="selected python:value == '-1'"
183188
i18n:translate="">unassigned</option>
184189
</tal:block>

share/roundup/templates/responsive/html/bug.search.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<th i18n:translate="">Creator:</th>
7474
<td metal:use-macro="search_input">
7575
<option metal:fill-slot="extra_options" i18n:translate=""
76-
tal:attributes="value request/user/id">created by me</option>
76+
value="@current_user"
77+
tal:attributes="selected python:value == '@current_user'">
78+
created by me</option>
7779
</td>
7880
<td metal:use-macro="column_input"></td>
7981
<td metal:use-macro="sort_input"></td>
@@ -94,7 +96,9 @@
9496
<th i18n:translate="">Last actor:</th>
9597
<td metal:use-macro="search_input">
9698
<option metal:fill-slot="extra_options" i18n:translate=""
97-
tal:attributes="value request/user/id">done by me</option>
99+
value="@current_user"
100+
tal:attributes="selected python:value == '@current_user'">
101+
done by me</option>
98102
</td>
99103
<td metal:use-macro="column_input"></td>
100104
<td metal:use-macro="sort_input"></td>
@@ -177,8 +181,9 @@
177181
<th i18n:translate="">Assigned to:</th>
178182
<td metal:use-macro="search_input">
179183
<tal:block metal:fill-slot="extra_options">
180-
<option tal:attributes="value request/user/id"
181-
i18n:translate="">assigned to me</option>
184+
<option value="@current_user"
185+
tal:attributes="selected python:value == '@current_user'"
186+
i18n:translate="">assigned to me</option>
182187
<option value="-1" tal:attributes="selected python:value == '-1'"
183188
i18n:translate="">unassigned</option>
184189
</tal:block>

share/roundup/templates/responsive/html/task.search.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<th i18n:translate="">Creator:</th>
7474
<td metal:use-macro="search_input">
7575
<option metal:fill-slot="extra_options" i18n:translate=""
76-
tal:attributes="value request/user/id">created by me</option>
76+
value="@current_user"
77+
tal:attributes="selected python:value == '@current_user'">
78+
created by me</option>
7779
</td>
7880
<td metal:use-macro="column_input"></td>
7981
<td metal:use-macro="sort_input"></td>
@@ -94,7 +96,9 @@
9496
<th i18n:translate="">Last actor:</th>
9597
<td metal:use-macro="search_input">
9698
<option metal:fill-slot="extra_options" i18n:translate=""
97-
tal:attributes="value request/user/id">done by me</option>
99+
value="@current_user"
100+
tal:attributes="selected python:value == '@current_user'">
101+
done by me</option>
98102
</td>
99103
<td metal:use-macro="column_input"></td>
100104
<td metal:use-macro="sort_input"></td>
@@ -151,8 +155,9 @@
151155
<th i18n:translate="">Assigned to:</th>
152156
<td metal:use-macro="search_input">
153157
<tal:block metal:fill-slot="extra_options">
154-
<option tal:attributes="value request/user/id"
155-
i18n:translate="">assigned to me</option>
158+
<option value="@current_user"
159+
tal:attributes="selected python:value == '@current_user'"
160+
i18n:translate="">assigned to me</option>
156161
<option value="-1" tal:attributes="selected python:value == '-1'"
157162
i18n:translate="">unassigned</option>
158163
</tal:block>

0 commit comments

Comments
 (0)