Searching by CurrentUser with QueryBuilder

Hi all,
I have a fresh 3.6.0 installation we’re customizing. We’d like to create
a saved search that searches for “Owner = ‘$RT::CurrentUser’” (as
opposed to a static username like “Owner = ‘drew’”), but this particular
syntax doesn’t work. Is this possible? If not, where would I start to
add this feature - we’d REALLY like to have it. :slight_smile:

Drew

Hi all,
I have a fresh 3.6.0 installation we’re customizing. We’d like to create
a saved search that searches for “Owner = ‘$RT::CurrentUser’” (as
opposed to a static username like “Owner = ‘drew’”), but this particular
syntax doesn’t work. Is this possible? If not, where would I start to
add this feature - we’d REALLY like to have it. :slight_smile:

Try: Owner = ‘CurrentUser

Thanks! That did the trick.

Drew-----Original Message-----
From: Todd Chapman [mailto:todd@chaka.net]
Sent: Monday, July 10, 2006 11:19 PM
To: Drew Taylor
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Searching by CurrentUser with QueryBuilder

On Mon, Jul 10, 2006 at 05:44:59PM -0400, Drew Taylor wrote:

Hi all,
I have a fresh 3.6.0 installation we’re customizing. We’d like to
create a saved search that searches for “Owner = ‘$RT::CurrentUser’”
(as opposed to a static username like “Owner = ‘drew’”), but this
particular syntax doesn’t work. Is this possible? If not, where would
I start to add this feature - we’d REALLY like to have it. :slight_smile:

Try: Owner = ‘CurrentUser

Thanks! That did the trick.

[…]

I have a fresh 3.6.0 installation we’re customizing. We’d like to
create a saved search that searches for “Owner = ‘$RT::CurrentUser’”
(as opposed to a static username like “Owner = ‘drew’”), but this
particular syntax doesn’t work. Is this possible? If not, where would
I start to add this feature - we’d REALLY like to have it. :slight_smile:

Try: Owner = ‘CurrentUser

I just created a test search under 3.6.0, and it doesn’t seem to be
giving me joy. Am I missing something here? The only search term is

Owner = ‘CurrentUser

and I get zero results.

(I own 20+ open tickets at the moment.)

This system was upgraded from 3.6.0rc0 through pre1/pre2/pre3 before
getting to the release version (I was impatient :slight_smile: so I suppose
something may have gotten bollixed during one of the upgrades… any
ideas where I should be checking?

/Ole Craig
Security Engineer

303-381-3802 (main support hotline)
303-381-3824 (my direct line)
303-381-3801 (fax)

www.stillsecure.com
. . .

Thanks! That did the trick.

[…]

I have a fresh 3.6.0 installation we’re customizing. We’d like to
create a saved search that searches for “Owner = ‘$RT::CurrentUser’”
(as opposed to a static username like “Owner = ‘drew’”), but this
particular syntax doesn’t work. Is this possible? If not, where would
I start to add this feature - we’d REALLY like to have it. :slight_smile:

Try: Owner = ‘CurrentUser

I just created a test search under 3.6.0, and it doesn’t seem to be
giving me joy. Am I missing something here? The only search term is

Owner = ‘CurrentUser

and I get zero results.

(I own 20+ open tickets at the moment.)

This system was upgraded from 3.6.0rc0 through pre1/pre2/pre3 before
getting to the release version (I was impatient :slight_smile: so I suppose
something may have gotten bollixed during one of the upgrades… any
ideas where I should be checking?

    The only place in the entire tree where __CurrentUser__ crops up

(aside from initialdata) is in /share/html/Elements/ShowSearch, which
only seems to be used for building the RT-at-a-glance page. In order to
get what I wanted working for my installation, I had to make the
following changes, and after playing with it for awhile I can’t
understand how the previous posters are getting results at all…

---- cut here 8< ----
diff -NauBb share/html/Search/Results.html local/html/Search/Results.html
— share/html/Search/Results.html 2006-01-19 20:50:58.000000000 -0700
+++ local/html/Search/Results.html 2006-07-20 22:53:43.000000000 -0600
@@ -54,7 +54,7 @@
OrderBy => $OrderBy,
Order => $Order &>
<& /Elements/TicketList,

  • Query => $Query,
  • Query => $NewQuery,
    AllowSorting => 1,
    OrderBy => $OrderBy,
    Order => $Order,
    @@ -113,11 +114,14 @@
    $Rows ||= 50;
    }

+# use CurrentUser in searches without clobbering the original string
+my $NewQuery;
+($NewQuery = $Query) =~ s/CurrentUser/$session{‘CurrentUser’}->Name/ge;

my ($title, $ticketcount);
$session{‘i’}++;
$session{‘tickets’} = RT::Tickets->new($session{‘CurrentUser’}) ;
-$session{‘tickets’}->FromSQL($Query) if ($Query);
+$session{‘tickets’}->FromSQL($NewQuery) if ($NewQuery);

if ($OrderBy =~ /|/) {
# Multiple Sorts
---- cut here 8< ----

/Ole Craig
Security Engineer

303-381-3802 (main support hotline)
303-381-3824 (my direct line)
303-381-3801 (fax)

www.stillsecure.com
. . .

Hey, why isn’t “Owner = ‘CurrentUser’” working for me? I can’t
figure this one out. It’s pretty simple it seems, but CurrentUser
isn’t getting replaced in the query:

Queue = ‘General’ AND Owner = ‘CurrentUser

What am I missing?

David Smithson

I think the problem is that the replacement of CurrentUser
with the user id is done in /Elements/ShowSearch. That is
only used for showing searches on the RT homepage. The link
at the top of the search is to the query builder with the
value replaced. Loading it from saved searches isn’t going to
work.

It would be better if the replacement was done in the
TicketSQL parser.

-ToddOn Mon, Jul 31, 2006 at 08:17:03PM -0700, David Smithson wrote:

Hey, why isn’t “Owner = ‘CurrentUser’” working for me? I can’t
figure this one out. It’s pretty simple it seems, but CurrentUser
isn’t getting replaced in the query:

Queue = ‘General’ AND Owner = ‘CurrentUser

What am I missing?

David Smithson


And I was just about to say that I only found the regexp in ShowSearch:

$SearchArg->{‘Query’} =~
s/CurrentUser/$session{‘CurrentUser’}->Id/ge;

I confirmed that you are right. The saved search does work from the
ataglance page.

I was actually trying to do some customization of the Quicksearch doodad
which resulted in lots of trying and nothing doing – if that makes any
sense. Clearly I have to put some thought into the context before I go
mucking about. So, in /Elements/Quicksearch under local, I have this:

<&|/Widgets/TitleBox, title => loc("Quick search"), bodyclass => "", titleright => loc("Edit"), titleright_href => $RT::WebPath.'/Prefs/Quicksearch.html' &> <& /Elements/QueueSummary, cache => 'quick_search_queues', queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') && !exists $unwanted->{$_->Name} }, conditions => [ {cond => "Status = 'new'", name => loc ('new') }, {cond => "Status = 'open'", name => loc ('open') }, {cond => "Status = 'stalled'", name => loc ('stalled') }, {cond => "Status = 'resolved'", name => loc ('resolved') }, {cond => "Owner = '__CurrentUser__'", name => loc ('mine') } ] &>
<%INIT> my $unwanted = $session{'CurrentUser'}->UserObj->Preferences('QuickSearch', {});

Hah! If only it were that simple.

David Smithson

CLICK HERE FOR ONLINE SUPPORTFrom: Todd Chapman [mailto:todd@chaka.net]
Sent: Monday, July 31, 2006 8:30 PM
To: David Smithson
Cc: Drew Taylor; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Searching by CurrentUser with QueryBuilder

I think the problem is that the replacement of CurrentUser
with the user id is done in /Elements/ShowSearch. That is
only used for showing searches on the RT homepage. The link
at the top of the search is to the query builder with the
value replaced. Loading it from saved searches isn’t going to
work.

It would be better if the replacement was done in the
TicketSQL parser.

-Todd

In RT::tickets::_WatcherLimit, try changing:

$o->Load($value);

to:

$o->Load( $value =~ /CurrentUser/ ? $self->CurrentUser->UserObj->Name : $value );

(that’s in lib/RT/Tickets_Ovelay.pm)

-ToddOn Mon, Jul 31, 2006 at 08:37:50PM -0700, David Smithson wrote:

And I was just about to say that I only found the regexp in ShowSearch:

$SearchArg->{‘Query’} =~
s/CurrentUser/$session{‘CurrentUser’}->Id/ge;

I confirmed that you are right. The saved search does work from the
ataglance page.

I was actually trying to do some customization of the Quicksearch doodad
which resulted in lots of trying and nothing doing – if that makes any
sense. Clearly I have to put some thought into the context before I go
mucking about. So, in /Elements/Quicksearch under local, I have this:

<&|/Widgets/TitleBox, title => loc("Quick search"), bodyclass => "", titleright => loc("Edit"), titleright_href => $RT::WebPath.'/Prefs/Quicksearch.html' &> <& /Elements/QueueSummary, cache => 'quick_search_queues', queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') && !exists $unwanted->{$_->Name} }, conditions => [ {cond => "Status = 'new'", name => loc ('new') }, {cond => "Status = 'open'", name => loc ('open') }, {cond => "Status = 'stalled'", name => loc ('stalled') }, {cond => "Status = 'resolved'", name => loc ('resolved') }, {cond => "Owner = '__CurrentUser__'", name => loc ('mine') } ] &>
<%INIT> my $unwanted = $session{'CurrentUser'}->UserObj->Preferences('QuickSearch', {});

Hah! If only it were that simple.

David Smithson


CLICK HERE FOR ONLINE SUPPORT

-----Original Message-----
From: Todd Chapman [mailto:todd@chaka.net]
Sent: Monday, July 31, 2006 8:30 PM
To: David Smithson
Cc: Drew Taylor; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Searching by CurrentUser with QueryBuilder

I think the problem is that the replacement of CurrentUser
with the user id is done in /Elements/ShowSearch. That is
only used for showing searches on the RT homepage. The link
at the top of the search is to the query builder with the
value replaced. Loading it from saved searches isn’t going to
work.

It would be better if the replacement was done in the
TicketSQL parser.

-Todd

On Mon, Jul 31, 2006 at 08:17:03PM -0700, David Smithson wrote:

Hey, why isn’t “Owner = ‘CurrentUser’” working for me? I can’t
figure this one out. It’s pretty simple it seems, but CurrentUser
isn’t getting replaced in the query:

Queue = ‘General’ AND Owner = ‘CurrentUser

What am I missing?

David Smithson


Yeah, that did the trick. Thanks Todd.

mkdir local/lib/RT
cp lib/RT/Tickets_Overlay.pm local/lib/RT/
vim +827 local/lib/RT/Tickets_Overlay.pm

David Smithson

CLICK HERE FOR ONLINE SUPPORTFrom: Todd Chapman [mailto:todd@chaka.net]
Sent: Monday, July 31, 2006 8:52 PM
To: David Smithson
Cc: Drew Taylor; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Searching by CurrentUser with QueryBuilder

In RT::tickets::_WatcherLimit, try changing:

$o->Load($value);

to:

$o->Load( $value =~ /CurrentUser/ ?
$self->CurrentUser->UserObj->Name : $value );

(that’s in lib/RT/Tickets_Ovelay.pm)

-Todd

And I was just about to say that I only found the regexp in
ShowSearch:

$SearchArg->{‘Query’} =~
s/CurrentUser/$session{‘CurrentUser’}->Id/ge;

I confirmed that you are right. The saved search does work from the
ataglance page.

I was actually trying to do some customization of the Quicksearch
doodad
which resulted in lots of trying and nothing doing – if that makes
any
sense. Clearly I have to put some thought into the context before I
go
mucking about. So, in /Elements/Quicksearch under local, I have this:

<&|/Widgets/TitleBox, title => loc("Quick search"), bodyclass => "", titleright => loc("Edit"), titleright_href => $RT::WebPath.'/Prefs/Quicksearch.html' &> <& /Elements/QueueSummary, cache => 'quick_search_queues', queue_filter => sub { $_->CurrentUserHasRight('ShowTicket') && !exists $unwanted->{$_->Name} }, conditions => [ {cond => "Status = 'new'", name => loc ('new') }, {cond => "Status = 'open'", name => loc ('open') }, {cond => "Status = 'stalled'", name => loc ('stalled') }, {cond => "Status = 'resolved'", name => loc ('resolved') }, {cond => "Owner = '__CurrentUser__'", name => loc ('mine') } ] &>
<%INIT> my $unwanted = $session{'CurrentUser'}->UserObj->Preferences('QuickSearch', {});

Hah! If only it were that simple.

David Smithson


CLICK HERE FOR ONLINE SUPPORT

-----Original Message-----
From: Todd Chapman [mailto:todd@chaka.net]
Sent: Monday, July 31, 2006 8:30 PM
To: David Smithson
Cc: Drew Taylor; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Searching by CurrentUser with QueryBuilder

I think the problem is that the replacement of CurrentUser
with the user id is done in /Elements/ShowSearch. That is
only used for showing searches on the RT homepage. The link
at the top of the search is to the query builder with the
value replaced. Loading it from saved searches isn’t going to
work.

It would be better if the replacement was done in the
TicketSQL parser.

-Todd

Hey, why isn’t “Owner = ‘CurrentUser’” working for me? I can’t
figure this one out. It’s pretty simple it seems, but
CurrentUser

isn’t getting replaced in the query:

Queue = ‘General’ AND Owner = ‘CurrentUser

What am I missing?

David Smithson