[Rt-commit] rt branch, 4.2/confirm-loaded-queue, created. rt-4.2.4rc1-8-g36c6c28

Jim Brandt jbrandt at bestpractical.com
Mon May 12 17:00:35 EDT 2014


The branch, 4.2/confirm-loaded-queue has been created
        at  36c6c285e87cf96d5b6a84695ef9881e2cf33e46 (commit)

- Log -----------------------------------------------------------------
commit 2c714ae3e79c4ca7d6f6a17f00c86c064f99ba12
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 12 16:23:03 2014 -0400

    Confirm loaded queue object before setting context object
    
    For cases where an invalid Queue value is passed as an arg,
    either a name or id of a non-existent queue or even 0, previously
    the emtpy queue object would still be set as the context object
    even though the load failed. This caused the search to add a
    Limit on a LookupType of RT::Queue, which won't find any
    custom fields.
    
    Check the return code to avoid setting the empty queue object and
    to warn so there is some help in the logs to track down a possible
    typo in the queue name/id.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index fdc66a2..520809d 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -417,10 +417,20 @@ sub LoadByName {
     # if we're looking for a queue by name, make it a number
     if ( defined $args{'Queue'} && ($args{'Queue'} =~ /\D/ || !$self->ContextObject) ) {
         my $QueueObj = RT::Queue->new( $self->CurrentUser );
-        $QueueObj->Load( $args{'Queue'} );
-        $args{'Queue'} = $QueueObj->Id;
-        $self->SetContextObject( $QueueObj )
-            unless $self->ContextObject;
+        my ($ret, $msg) = $QueueObj->Load( $args{'Queue'} );
+
+        # Only set the context object if we successfully loaded a queue.
+        # This avoids creating a LookupType of RT::Queue below based on an empty
+        # queue object.
+
+        if ( $ret ){
+            $args{'Queue'} = $QueueObj->Id;
+            $self->SetContextObject( $QueueObj )
+                unless $self->ContextObject;
+        }
+        else {
+            RT::Logger->warning("Unable to load queue with id " . $args{'Queue'});
+        }
     }
     if ( defined $args{'Queue'} ) {
         # Set a LookupType for backcompat, otherwise we'll calculate

commit 36c6c285e87cf96d5b6a84695ef9881e2cf33e46
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 12 16:35:46 2014 -0400

    Explicitly exclude 0 from queue lookup
    
    A Queue value of 0 represents a global CF, but will not load a
    queue successfully. Explicitly exclude 0 from the queue load and
    context object setting. Although 2c714ae3 will now prevent this,
    it logs a warning that is inappropriate when using the documented
    API for the method.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 520809d..22f5684 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -415,7 +415,10 @@ sub LoadByName {
     }
 
     # if we're looking for a queue by name, make it a number
-    if ( defined $args{'Queue'} && ($args{'Queue'} =~ /\D/ || !$self->ContextObject) ) {
+    # Exclude 0 since it is a valid parameter, but will not load a valid queue
+    if ( defined $args{'Queue'}
+         && $args{'Queue'} != 0
+         && ($args{'Queue'} =~ /\D/ || !$self->ContextObject) ) {
         my $QueueObj = RT::Queue->new( $self->CurrentUser );
         my ($ret, $msg) = $QueueObj->Load( $args{'Queue'} );
 

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


More information about the rt-commit mailing list