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

Alex Vandiver alexmv at bestpractical.com
Tue Dec 31 16:12:42 EST 2013


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

- Log -----------------------------------------------------------------
commit a83610776ca6ad18076d899e24126a615be8b879
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..c72be1a 100644
--- a/share/html/Search/Elements/BuildFormatString
+++ b/share/html/Search/Elements/BuildFormatString
@@ -107,6 +107,7 @@ foreach my $id (keys %queues) {
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
     $CustomFields->LimitToQueue($queue->Id) if $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..e0fd41a 100644
--- a/share/html/Search/Elements/PickObjectCFs
+++ b/share/html/Search/Elements/PickObjectCFs
@@ -59,6 +59,7 @@ foreach my $name (keys %queues) {
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($name);
     $CustomFields->LimitToObjectId($queue->Id) if $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..44bbef1 100644
--- a/share/html/Search/Elements/PickTicketCFs
+++ b/share/html/Search/Elements/PickTicketCFs
@@ -55,6 +55,7 @@ foreach my $id (keys %queues) {
     my $queue = RT::Queue->new($session{'CurrentUser'});
     $queue->Load($id);
     $CustomFields->LimitToQueue($queue->Id) if $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