[Rt-commit] rt branch, 4.0/querybuilder-queue-limits, created. rt-4.0.2-123-g8356324

Alex Vandiver alexmv at bestpractical.com
Thu Sep 29 13:35:34 EDT 2011


The branch, 4.0/querybuilder-queue-limits has been created
        at  835632495ff424892ae8d67e26a726959855878d (commit)

- Log -----------------------------------------------------------------
commit 8ba9858f9827e5e499f9e12f2feb42898f4b491c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Sep 28 18:07:09 2011 -0400

    Fix quoting in GetReferencedQueues to return useful keys in the hash
    
    Previously, GetReferencedQueues returned queue names (including the
    outer quotes, with internal escaping preserved) or possibly queue ids,
    exactly as they were in the TicketSQL.  The code which used this return
    value had to correctly strip the outer quotes, as well as remove the
    escaping.  They chose to do this with a perplexing regex which worked
    more by accident than anything else, and did the unescaping improperly
    or not at all.
    
    Standardize on returning the names in a manner suitable to be passed
    unmodified to $queue->Load.

diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
index 860485e..fba5e06 100644
--- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm
+++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
@@ -110,10 +110,11 @@ sub GetReferencedQueues {
             return unless $node->isLeaf;
 
             my $clause = $node->getNodeValue();
+            return unless $clause->{Key} eq 'Queue';
 
-            if ( $clause->{Key} eq 'Queue' ) {
-                $queues->{ $clause->{Value} } = 1;
-            };
+            my $value = $clause->{Value};
+            $value =~ s/\\(.)/$1/g if $value =~ s/^'(.*)'$/$1/;
+            $queues->{ $value } = 1;
         }
     );
 
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 32eb4cc..5012ae2 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -89,13 +89,7 @@ sub Groupings {
         foreach my $id (keys %$queues) {
             my $queue = RT::Queue->new( $self->CurrentUser );
             $queue->Load($id);
-            unless ($queue->id) {
-                # XXX TODO: This ancient code dates from a former developer
-                # we have no idea what it means or why cfqueues are so encoded.
-                $id =~ s/^.'*(.*).'*$/$1/;
-                $queue->Load($id);
-            }
-            $CustomFields->LimitToQueue($queue->Id);
+            $CustomFields->LimitToQueue($queue->Id) if $queue->Id;
         }
         $CustomFields->LimitToGlobal;
         while ( my $CustomField = $CustomFields->Next ) {
diff --git a/share/html/Search/Elements/BuildFormatString b/share/html/Search/Elements/BuildFormatString
index 89ac642..0c7166f 100644
--- a/share/html/Search/Elements/BuildFormatString
+++ b/share/html/Search/Elements/BuildFormatString
@@ -105,13 +105,7 @@ foreach my $id (keys %cfqueues) {
     # Gotta load up the $queue object, since queues get stored by name now. my $id
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
-    unless ($queue->id) {
-        # XXX TODO: This ancient code dates from a former developer
-        # we have no idea what it means or why cfqueues are so encoded.
-        $id =~ s/^.'*(.*).'*$/$1/;
-        $queue->Load($id);
-    }
-    $CustomFields->LimitToQueue($queue->Id);
+    $CustomFields->LimitToQueue($queue->Id) if $queue->Id;
 }
 $CustomFields->LimitToGlobal;
 
diff --git a/share/html/Search/Elements/PickCFs b/share/html/Search/Elements/PickCFs
index f3ae629..7be88cb 100644
--- a/share/html/Search/Elements/PickCFs
+++ b/share/html/Search/Elements/PickCFs
@@ -54,17 +54,7 @@ foreach my $id (keys %cfqueues) {
     # Gotta load up the $queue object, since queues get stored by name now. my $id
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
-    unless ($queue->id) {
-        # XXX TODO: This ancient code dates from a former developer
-        # we have no idea what it means or why cfqueues are so encoded.
-        $id =~ s/^.'*(.*).'*$/$1/;
-
-        # unescape internal quotes
-        $id =~ s/(\\(.))/$2 eq "'" ? "'" : $1/eg;
-
-        $queue->Load($id);
-    }
-    $CustomFields->LimitToQueue($queue->Id);
+    $CustomFields->LimitToQueue($queue->Id) if $queue->Id;
 }
 $CustomFields->LimitToGlobal;
 $m->callback(

commit cbef7ff03232d909bc8b6682ba4aa1c004291dbf
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Sep 28 21:49:22 2011 -0400

    Only return queues which were referenced explicitly and positively
    
    Previously, a TicketSQL query of << Queue != 'General' >> would
    incorrectly limit the custom fields in the QueryBuilder to those on the
    General queue.  Since limiting to only queues referenced with the '='
    operator is nearly always more correct, only return those queues.  While
    this is clearly insufficient to solve the more general problem (it still
    fails on << Queue = 'General' OR Queue != 'General' >>, for example), it
    in general produces more correct results.

diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
index fba5e06..0329289 100644
--- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm
+++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
@@ -92,8 +92,8 @@ sub TraversePrePost {
 
 =head2 GetReferencedQueues
 
-Returns a hash reference with keys each queue name referenced in a clause in
-the key (even if it's "Queue != 'Foo'"), and values all 1.
+Returns a hash reference; each queue referenced with an '=' operation
+will appear as a key whose value is 1.
 
 =cut
 
@@ -111,6 +111,7 @@ sub GetReferencedQueues {
 
             my $clause = $node->getNodeValue();
             return unless $clause->{Key} eq 'Queue';
+            return unless $clause->{Op} eq '=';
 
             my $value = $clause->{Value};
             $value =~ s/\\(.)/$1/g if $value =~ s/^'(.*)'$/$1/;

commit 67ed6217e1a02b8a10c98018e834c5cea2e16414
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Sep 28 21:46:03 2011 -0400

    Rename cfqueues parameter to imply its more general utility

diff --git a/share/html/Elements/SelectOwner b/share/html/Elements/SelectOwner
index ef10cd1..c67879f 100755
--- a/share/html/Elements/SelectOwner
+++ b/share/html/Elements/SelectOwner
@@ -55,8 +55,8 @@ if ($TicketObj) {
     @objects = ($TicketObj);
 } elsif ($QueueObj) {
     @objects = ($QueueObj);
-} elsif ($cfqueues) {
-    @objects = keys %{$cfqueues};
+} elsif ($Queues) {
+    @objects = keys %{$Queues};
 } else {
     # Let's check rights on an empty queue object. that will do a search
     # for any queue.
@@ -73,5 +73,5 @@ $m->callback(
 <%ARGS>
 $TicketObj  => undef
 $QueueObj   => undef
-$cfqueues   => undef
+$Queues   => undef
 </%ARGS>
diff --git a/share/html/Elements/SelectStatus b/share/html/Elements/SelectStatus
index 1735800..2bbcf7d 100644
--- a/share/html/Elements/SelectStatus
+++ b/share/html/Elements/SelectStatus
@@ -88,6 +88,7 @@ $Name => undef
 @Statuses => ()
 $TicketObj => undef
 $QueueObj => undef
+%Queues => ()
 
 $Default => ''
 $SkipDeleted => 0
diff --git a/share/html/Prefs/Search.html b/share/html/Prefs/Search.html
index 0b97e31..e007d60 100644
--- a/share/html/Prefs/Search.html
+++ b/share/html/Prefs/Search.html
@@ -95,7 +95,7 @@ $ARGS{'OrderBy'} = join '|', grep defined && /\S/, (ref $ARGS{'OrderBy'})? @{$AR
 my ( $AvailableColumns, $CurrentFormat );
 ( $ARGS{Format}, $AvailableColumns, $CurrentFormat ) = $m->comp(
     '/Search/Elements/BuildFormatString',
-    cfqueues => {}, %ARGS
+    %ARGS
 );
 
 if ($ARGS{'Save'}) {
diff --git a/share/html/Search/Build.html b/share/html/Search/Build.html
index e23eb5a..cd35a2c 100644
--- a/share/html/Search/Build.html
+++ b/share/html/Search/Build.html
@@ -78,7 +78,7 @@
 
 
 <div id="pick-criteria">
-    <& Elements/PickCriteria, query => $query{'Query'}, cfqueues => $queues &>
+    <& Elements/PickCriteria, query => $query{'Query'}, queues => $queues &>
 </div>
 <& /Elements/Submit,  Label => loc('Add these terms'), SubmitId => 'AddClause', Name => 'AddClause'&>
 <& /Elements/Submit, Label => loc('Add these terms and Search'), SubmitId => 'DoSearch', Name => 'DoSearch'&>
@@ -269,7 +269,7 @@ my ( $AvailableColumns, $CurrentFormat );
 ( $query{'Format'}, $AvailableColumns, $CurrentFormat ) = $m->comp(
     'Elements/BuildFormatString',
     %ARGS,
-    cfqueues => $queues,
+    queues => $queues,
     Format => $query{'Format'},
 );
 
diff --git a/share/html/Search/Elements/BuildFormatString b/share/html/Search/Elements/BuildFormatString
index 0c7166f..b169c98 100644
--- a/share/html/Search/Elements/BuildFormatString
+++ b/share/html/Search/Elements/BuildFormatString
@@ -48,7 +48,7 @@
 <%ARGS>
 $Format => RT->Config->Get('DefaultSearchResultFormat')
 
-%cfqueues => ()
+%queues => ()
 
 $Face => undef
 $Size => undef
@@ -101,7 +101,7 @@ my @fields = qw(
 $m->callback( CallbackOnce => 1, CallbackName => 'SetFieldsOnce', Fields => \@fields );
 
 my $CustomFields = RT::CustomFields->new( $session{'CurrentUser'});
-foreach my $id (keys %cfqueues) {
+foreach my $id (keys %queues) {
     # Gotta load up the $queue object, since queues get stored by name now. my $id
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
diff --git a/share/html/Search/Elements/PickCFs b/share/html/Search/Elements/PickCFs
index 7be88cb..86441d8 100644
--- a/share/html/Search/Elements/PickCFs
+++ b/share/html/Search/Elements/PickCFs
@@ -50,8 +50,8 @@
 % }
 <%INIT>
 my $CustomFields = RT::CustomFields->new( $session{'CurrentUser'});
-foreach my $id (keys %cfqueues) {
-    # Gotta load up the $queue object, since queues get stored by name now. my $id
+foreach my $id (keys %queues) {
+    # Gotta load up the $queue object, since queues get stored by name now.
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
     $CustomFields->LimitToQueue($queue->Id) if $queue->Id;
@@ -114,10 +114,10 @@ while ( my $CustomField = $CustomFields->Next ) {
     push @lines, \%line;
 }
 
-$m->callback( Conditions => \@lines, Queues => \%cfqueues );
+$m->callback( Conditions => \@lines, Queues => \%queues );
 
 </%INIT>
 
 <%ARGS>
-%cfqueues => undef
+%queues => undef
 </%ARGS>
diff --git a/share/html/Search/Elements/PickCriteria b/share/html/Search/Elements/PickCriteria
index 44e3b70..b05bdfd 100644
--- a/share/html/Search/Elements/PickCriteria
+++ b/share/html/Search/Elements/PickCriteria
@@ -52,7 +52,7 @@
 
 
 <& PickBasics &>
-<& PickCFs, cfqueues => \%cfqueues &>
+<& PickCFs, queues => \%queues &>
 
 <tr class="separator"><td colspan="3"><hr /></td></tr>
 <tr>
@@ -68,5 +68,5 @@
 <%ARGS>
 $addquery => 0
 $query => undef
-%cfqueues => undef
+%queues => undef
 </%ARGS>

commit 13c9428055fda4e3e383cd0b474dee1ecad988d7
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Sep 28 21:46:58 2011 -0400

    QueryBuilder: Limit possible owners based on selected queues

diff --git a/share/html/Elements/SelectOwner b/share/html/Elements/SelectOwner
index c67879f..43f051f 100755
--- a/share/html/Elements/SelectOwner
+++ b/share/html/Elements/SelectOwner
@@ -55,8 +55,16 @@ if ($TicketObj) {
     @objects = ($TicketObj);
 } elsif ($QueueObj) {
     @objects = ($QueueObj);
-} elsif ($Queues) {
-    @objects = keys %{$Queues};
+} elsif (%Queues) {
+    for my $name (keys %Queues) {
+        if (ref $name) {
+            push @objects, $name;
+        } else {
+            my $q = RT::Queue->new($session{'CurrentUser'});
+            $q->Load($name);
+            push @objects, $q;
+        }
+    }
 } else {
     # Let's check rights on an empty queue object. that will do a search
     # for any queue.
@@ -73,5 +81,5 @@ $m->callback(
 <%ARGS>
 $TicketObj  => undef
 $QueueObj   => undef
-$Queues   => undef
+%Queues     => ()
 </%ARGS>
diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index b03fc15..5bc3ea3 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -124,7 +124,7 @@ my @lines = (
         Value => {
             Type => 'component',
             Path => '/Elements/SelectOwner',
-            Arguments => { ValueAttribute => 'Name' },
+            Arguments => { ValueAttribute => 'Name', Queues => \%queues },
         },
     },
     {
@@ -212,3 +212,6 @@ my @lines = (
 $m->callback( Conditions => \@lines );
 
 </%INIT>
+<%ARGS>
+%queues => ()
+</%ARGS>
diff --git a/share/html/Search/Elements/PickCriteria b/share/html/Search/Elements/PickCriteria
index b05bdfd..5be8e98 100644
--- a/share/html/Search/Elements/PickCriteria
+++ b/share/html/Search/Elements/PickCriteria
@@ -51,7 +51,7 @@
 
 
 
-<& PickBasics &>
+<& PickBasics, queues => \%queues &>
 <& PickCFs, queues => \%queues &>
 
 <tr class="separator"><td colspan="3"><hr /></td></tr>

commit 835632495ff424892ae8d67e26a726959855878d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Sep 28 21:47:28 2011 -0400

    QueryBuilder: Limit possible statuses based on selected queues

diff --git a/share/html/Elements/SelectStatus b/share/html/Elements/SelectStatus
index 2bbcf7d..7c0eb0c 100644
--- a/share/html/Elements/SelectStatus
+++ b/share/html/Elements/SelectStatus
@@ -77,8 +77,15 @@ elsif ( $TicketObj ) {
 }
 elsif ( $QueueObj ) {
     @status = $QueueObj->Lifecycle->Transitions('');
-}
-else {
+} elsif ( %Queues ) {
+    for my $id (keys %Queues) {
+        my $queue = RT::Queue->new($session{'CurrentUser'});
+        $queue->Load($id);
+        push @status, $queue->Lifecycle->Valid if $queue->id;
+    }
+    my %seen;
+    @status = grep { not $seen{$_}++ } @status;
+} else {
     @status = RT::Queue->Lifecycle->Valid;
 }
 </%INIT>
diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index 5bc3ea3..2c7f485 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -103,7 +103,7 @@ my @lines = (
         Value => {
             Type => 'component',
             Path => '/Elements/SelectStatus',
-            Arguments => { SkipDeleted => 1 },
+            Arguments => { SkipDeleted => 1, Queues => \%queues },
         },
     },
     {

-----------------------------------------------------------------------


More information about the Rt-commit mailing list