Edgewall Software

Ticket #1467 (closed enhancement: fixed)

Opened 3 years ago

Last modified 5 weeks 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@…

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 (0.7 kB) - added by muti@… 3 years ago.

Change History

Changed 3 years ago by muti@…

  Changed 3 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.

  Changed 3 years ago by cmlenz

  • milestone changed from 0.9 to 0.9.1

  Changed 3 years ago by cmlenz

  • milestone changed from 0.9.1 to 0.9.2

  Changed 3 years ago by cmlenz

  • milestone changed from 0.9.3 to 1.0

  Changed 23 months ago by cboos

  • owner changed from cmlenz to cboos
  • milestone changed from 1.0 to 0.11

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

  Changed 23 months ago by cboos

  • status changed from new to closed
  • resolution set to fixed

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.

  Changed 17 months 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]

  Changed 17 months ago by cboos

  • status changed from closed to reopened
  • resolution fixed deleted

Ok, I'll look into this.

  Changed 17 months ago by cboos

  • status changed from reopened to closed
  • resolution set to fixed

Fixed in r5195. Thanks for the report!

  Changed 17 months ago by mgood

  • status changed from closed to reopened
  • resolution fixed deleted

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.

  Changed 17 months ago by mgood

  • owner changed from cboos to mgood
  • status changed from reopened to new

  Changed 17 months 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.

  Changed 16 months ago by cboos

  • status changed from new to closed
  • resolution set to fixed

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

follow-up: ↓ 16   Changed 4 months ago by Marcin Wojdyr <wojdyr@…>

  • status changed from closed to reopened
  • resolution fixed deleted

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

  Changed 4 months ago by Kamil Kisiel <kamil@…>

There's also the problem in #7258

in reply to: ↑ 14   Changed 8 weeks 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) 

  Changed 5 weeks ago by osimons

  • status changed from new to closed
  • resolution set to fixed

Committed in [7445:7446].

Add/Change #1467 (Custom Query should support a dynamic $USER variable)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.