Opened 20 years ago
Closed 16 years ago
#1467 closed enhancement (fixed)
Custom Query should support a dynamic $USER variable
Reported by: | Owned by: | osimons | |
---|---|---|---|
Priority: | low | Milestone: | 0.11.1 |
Component: | report system | Version: | devel |
Severity: | normal | Keywords: | custom query user |
Cc: | muti@…, sdyson@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
I'm making the custom query module the default for View Tickets and am moving a list of reports to the Wiki using query: syntax. One limitation so far is that there is no support for a "My Tickets" query:. The attached patch allows $USER replacement with the active user so that query?status=new&status=assigned&status=reopened&owner=$USER will show all tickets owned by the user clicking the link.
It will also work with multiple users, i.e. query?owner=$USER&owner=joeblow, and the is not restriction, i.e. query?owner=!$USER.
Attachments (1)
Change History (18)
by , 20 years ago
Attachment: | Query.py.diff added |
---|
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Milestone: | 0.9 → 0.9.1 |
---|
comment:3 by , 19 years ago
Milestone: | 0.9.1 → 0.9.2 |
---|
comment:4 by , 19 years ago
Milestone: | 0.9.3 → 1.0 |
---|
comment:5 by , 18 years ago
Milestone: | 1.0 → 0.11 |
---|---|
Owner: | changed from | to
#3967 requested the same thing but for the [[TicketQuery]] macro, so we'll probably do both together.
comment:6 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Implemented in r3999.
Note that in the unlikely case you'd like to match something which ends with the 'USER' string, you'd have to use $=USER
instead of =$USER
.
comment:7 by , 18 years ago
Cc: | added |
---|
This fix works for queries defined using TracQuery#QueryLanguage but doesn't work when the query string has been copied complete with the ?.
e.g. this works:
[query:status=new|assigned|reopened&owner=$USER My Tickets]
this does not:
[query:?status=new&status=assigned&status=reopened&owner=$USER My Tickets]
comment:9 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Fixed in r5195. Thanks for the report!
comment:10 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:11 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:12 by , 18 years ago
Owner: | changed from | to
---|
comment:13 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Works now as expected, with no changes to the 0.10 API.
follow-up: 16 comment:14 by , 17 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
the SQL query is generated as expected and the list of results is also correct, but there is one minor issue.
If the query is, say, "owner=$USER" in the filters box on query page instead of: owner is foo there is: owner ends with USER
tested in 0.11rc1
comment:16 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
Replying to Marcin Wojdyr:
If the query is, say, "owner=$USER" in the filters box on query page instead of: owner is foo there is: owner ends with USER
Verified, and this is quite tricky. Trac uses the $
as marker for 'endswith', so that if you actually do an endswith $USER
selection it works correctly - it gets like user=$$USER
in query string, strips one off, and keeps the remainder correctly.
The problem is when you use 'is' that has no defined prefix. The double useage of $
means that Trac cannot distinguish between is $USER
and endswith USER
as the querystring for both will look like owner=$USER
. Trac selects the latter, but we could change that to test specially for known substitutions first and always prefer that interpretation.
Certainly as both default queries know contain $USER
, the changed strategy is likely to be more right than wrong - although as long as the double meaning is maintained, we could always get cases that gets interpreted wrong.
Below is a 0.11-stable patch that changes the evaluation for known substitutions - please test:
-
trac/ticket/query.py
61 61 self.groupdesc = groupdesc 62 62 self.default_page = 1 63 63 self.items_per_page = QueryModule(self.env).items_per_page 64 self.substitutions = ['$USER'] 64 65 65 66 # getting page number (default_page if unspecified) 66 67 if not page: … … 134 135 raise QuerySyntaxError(_('Query filter requires field name')) 135 136 # from last char of `field`, get the mode of comparison 136 137 mode, neg = '', '' 137 if field[-1] in ('~', '^', '$'): 138 if field[-1] in ('~', '^', '$') \ 139 and not field in self.substitutions: 138 140 mode = field[-1] 139 141 field = field[:-1] 140 142 if field[-1] == '!': … … 570 572 if neg: 571 573 val = val[1:] 572 574 mode = '' 573 if val[:1] in ('~', '^', '$'): 575 if val[:1] in ('~', '^', '$') \ 576 and not val in self.substitutions: 574 577 mode, val = val[:1], val[1:] 575 578 constraint['mode'] = (neg and '!' or '') + mode 576 579 constraint['values'].append(val)
I think it might make more sense to put this support into the query string parser, so that you could use this variable from the
TicketQuery
macro andquery:
links.