Edgewall Software
Modify

Opened 19 years ago

Closed 16 years ago

#1467 closed enhancement (fixed)

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@… 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)

Query.py.diff (748 bytes ) - added by muti@… 19 years ago.

Download all attachments as: .zip

Change History (18)

by muti@…, 19 years ago

Attachment: Query.py.diff added

comment:1 by Christopher Lenz, 19 years ago

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.

comment:2 by Christopher Lenz, 19 years ago

Milestone: 0.90.9.1

comment:3 by Christopher Lenz, 18 years ago

Milestone: 0.9.10.9.2

comment:4 by Christopher Lenz, 18 years ago

Milestone: 0.9.31.0

comment:5 by Christian Boos, 18 years ago

Milestone: 1.00.11
Owner: changed from Christopher Lenz to Christian Boos

#3967 requested the same thing but for the [[TicketQuery]] macro, so we'll probably do both together.

comment:6 by Christian Boos, 18 years ago

Resolution: fixed
Status: newclosed

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 anonymous, 17 years ago

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 by Christian Boos, 17 years ago

Resolution: fixed
Status: closedreopened

Ok, I'll look into this.

comment:9 by Christian Boos, 17 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in r5195. Thanks for the report!

comment:10 by Matthew Good, 17 years ago

Resolution: fixed
Status: closedreopened

r3999 and r5195 both make changes to the public API. I'm working on a simple fix for this that does not break the API.

comment:11 by Matthew Good, 17 years ago

Owner: changed from Christian Boos to Matthew Good
Status: reopenednew

comment:12 by Christian Boos, 17 years ago

Owner: changed from Matthew Good to Christian Boos

You're right, the API unnecessarily changed from 0.10 due to the above changesets. I've fixed that in r5217.

But I think the feature itself as implemented in r5195 is OK, let me know if you think we can close this one now.

comment:13 by Christian Boos, 17 years ago

Resolution: fixed
Status: newclosed

Works now as expected, with no changes to the 0.10 API.

comment:14 by Marcin Wojdyr <wojdyr@…>, 16 years ago

Resolution: fixed
Status: closedreopened

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 by Kamil Kisiel <kamil@…>, 16 years ago

There's also the problem in #7258

in reply to:  14 comment:16 by osimons, 16 years ago

Owner: changed from Christian Boos to osimons
Status: reopenednew

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

     
    6161        self.groupdesc = groupdesc
    6262        self.default_page = 1
    6363        self.items_per_page = QueryModule(self.env).items_per_page
     64        self.substitutions = ['$USER']
    6465
    6566        # getting page number (default_page if unspecified)
    6667        if not page:
     
    134135                raise QuerySyntaxError(_('Query filter requires field name'))
    135136            # from last char of `field`, get the mode of comparison
    136137            mode, neg = '', ''
    137             if field[-1] in ('~', '^', '$'):
     138            if field[-1] in ('~', '^', '$') \
     139                                and not field in self.substitutions:
    138140                mode = field[-1]
    139141                field = field[:-1]
    140142            if field[-1] == '!':
     
    570572                if neg:
    571573                    val = val[1:]
    572574                mode = ''
    573                 if val[:1] in ('~', '^', '$'):
     575                if val[:1] in ('~', '^', '$') \
     576                                    and not val in self.substitutions:
    574577                    mode, val = val[:1], val[1:]
    575578                constraint['mode'] = (neg and '!' or '') + mode
    576579                constraint['values'].append(val)

comment:17 by osimons, 16 years ago

Resolution: fixed
Status: newclosed

Committed in [7445:7446].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from osimons to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.