Edgewall Software
Modify

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

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

Download all attachments as: .zip

Change History

Changed 7 years ago by muti@…

comment:1 Changed 6 years ago by cmlenz

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 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

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 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

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 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: 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

     
    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 Changed 4 years ago by osimons

  • Resolution set to fixed
  • Status changed from new to closed

Committed in [7445:7446].

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from osimons. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.