[Rt-commit] rt branch, 4.2/single-queue-search-contextobj, created. rt-4.2.1-149-g2078d6b

Alex Vandiver alexmv at bestpractical.com
Mon Jan 6 18:09:24 EST 2014


The branch, 4.2/single-queue-search-contextobj has been created
        at  2078d6b5f98d98979044724970844d5ddc111bf3 (commit)

- Log -----------------------------------------------------------------
commit 2078d6b5f98d98979044724970844d5ddc111bf3
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 31 15:57:34 2013 -0500

    Allow queue CF rights to apply on single-queue searches
    
    Because of the lack of context object, granting a user SeeCustomField on
    a queue was insufficient to cause its CFs to appear if the search was
    limited to that queue.  While CFs cannot currently have more than one
    context object (as would be necessary in the case of a search over
    multiple queues), the usability can be improved in the common case of a
    limit on a single queue.
    
    Apply the relevant queue as context object to CF limits when searching
    within a single queue.  This allows "SeeCustomField" on the queue level
    to be respected in the SearchBuilder.

diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index fb4d816..16c1c8b 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -158,6 +158,7 @@ size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
 $cfs->LimitToGlobal();
 $cfs->LimitToQueue($_) for keys %$seen_queues;
+$cfs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
 </%perl>
 
 % if ( $cfs->Count ) {
@@ -230,7 +231,8 @@ Abort( loc("No search to operate on.") ) unless ($Tickets);
 my $fields      = {};
 my $seen_queues = {};
 while ( my $ticket = $Tickets->Next ) {
-    next if $seen_queues->{ $ticket->Queue }++;
+    next if $seen_queues->{ $ticket->Queue };
+    $seen_queues->{ $ticket->Queue } ||= $ticket->QueueObj;
 
     my $custom_fields = $ticket->CustomFields;
     while ( my $field = $custom_fields->Next ) {
@@ -289,6 +291,7 @@ unless ( $ARGS{'AddMoreAttach'} ) {
 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
 $TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
+$TxnCFs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
 
 </%INIT>
 <%args>
diff --git a/share/html/Search/Elements/BuildFormatString b/share/html/Search/Elements/BuildFormatString
index da7797e..b344683 100644
--- a/share/html/Search/Elements/BuildFormatString
+++ b/share/html/Search/Elements/BuildFormatString
@@ -106,7 +106,9 @@ 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;
+    next unless $queue->Id;
+    $CustomFields->LimitToQueue($queue->Id);
+    $CustomFields->SetContextObject( $queue ) if keys %queues == 1;
 }
 $CustomFields->LimitToGlobal;
 
diff --git a/share/html/Search/Elements/PickObjectCFs b/share/html/Search/Elements/PickObjectCFs
index e5671a5..07c3573 100644
--- a/share/html/Search/Elements/PickObjectCFs
+++ b/share/html/Search/Elements/PickObjectCFs
@@ -58,7 +58,9 @@ $CustomFields->LimitToObjectId(0);
 foreach my $name (keys %queues) {
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($name);
-    $CustomFields->LimitToObjectId($queue->Id) if $queue->Id;
+    next unless $queue->Id;
+    $CustomFields->LimitToObjectId($queue->Id);
+    $CustomFields->SetContextObject( $queue ) if keys %queues == 1;
 }
 
 my $has_cf = $CustomFields->First ? 1 : 0;
diff --git a/share/html/Search/Elements/PickTicketCFs b/share/html/Search/Elements/PickTicketCFs
index 86097f8..2f94d28 100644
--- a/share/html/Search/Elements/PickTicketCFs
+++ b/share/html/Search/Elements/PickTicketCFs
@@ -54,7 +54,9 @@ 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;
+    next unless $queue->Id;
+    $CustomFields->LimitToQueue($queue->Id);
+    $CustomFields->SetContextObject( $queue ) if keys %queues == 1;
 }
 $CustomFields->LimitToGlobal;
 $CustomFields->OrderBy( FIELD => 'Name', ORDER => 'ASC' );

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


More information about the rt-commit mailing list