Ticket #1467 (closed enhancement: fixed)
Opened 7 years ago
Last modified 4 years ago
Custom Query should support a dynamic $USER variable
| Reported by: | muti@… | Owned by: | osimons |
|---|---|---|---|
| Priority: | low | Milestone: | 0.11.1 |
| Component: | report system | Version: | devel |
| Severity: | normal | Keywords: | custom query user |
| Cc: | muti@…, sdyson@… | ||
| Release Notes: | |||
| API 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
Change History
Changed 7 years ago by muti@…
- Attachment Query.py.diff added
comment:1 Changed 6 years ago by cmlenz
comment:2 Changed 6 years ago by cmlenz
- Milestone changed from 0.9 to 0.9.1
comment:3 Changed 6 years ago by cmlenz
- Milestone changed from 0.9.1 to 0.9.2
comment:4 Changed 6 years ago by cmlenz
- Milestone changed from 0.9.3 to 1.0
comment:5 Changed 5 years ago by cboos
- Milestone changed from 1.0 to 0.11
- Owner changed from cmlenz to cboos
#3967 requested the same thing but for the [[TicketQuery]] macro, so we'll probably do both together.
comment:6 Changed 5 years ago by cboos
- Resolution set to fixed
- Status changed from new to 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 Changed 5 years ago by anonymous
- Cc sdyson@… 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:8 Changed 5 years ago by cboos
- Resolution fixed deleted
- Status changed from closed to reopened
Ok, I'll look into this.
comment:9 Changed 5 years ago by cboos
- Resolution set to fixed
- Status changed from reopened to closed
Fixed in r5195. Thanks for the report!
comment:10 Changed 5 years ago by mgood
- Resolution fixed deleted
- Status changed from closed to reopened
comment:11 Changed 5 years ago by mgood
- Owner changed from cboos to mgood
- Status changed from reopened to new
comment:12 Changed 5 years ago by cboos
- Owner changed from mgood to cboos
comment:13 Changed 5 years ago by cboos
- Resolution set to fixed
- Status changed from new to closed
Works now as expected, with no changes to the 0.10 API.
comment:14 follow-up: ↓ 16 Changed 4 years ago by Marcin Wojdyr <wojdyr@…>
- Resolution fixed deleted
- Status changed from closed to 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:15 Changed 4 years ago by Kamil Kisiel <kamil@…>
There's also the problem in #7258
comment:16 in reply to: ↑ 14 Changed 4 years ago by osimons
- Owner changed from cboos to osimons
- Status changed from reopened to 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)
comment:17 Changed 4 years ago by osimons
- Resolution set to fixed
- Status changed from new to closed
Committed in [7445:7446].



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 and query: links.