[Rt-commit] rt branch, 4.2/initialdata-cf-lookuptype, created. rt-4.1.13-73-g201b964

Alex Vandiver alexmv at bestpractical.com
Wed Jul 3 13:34:51 EDT 2013


The branch, 4.2/initialdata-cf-lookuptype has been created
        at  201b964ff69e8de48bcd60369346d2eef5fec0a3 (commit)

- Log -----------------------------------------------------------------
commit e2c21b55e8b6dd94e0e4268d4cf948982f056fc7
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jul 3 12:54:46 2013 -0400

    Allow limiting of LookupType in RT::CustomField->LoadByName
    
    Most of the time, when a Name is supplied, only one LookupType is valid.
    If multiple CFs with the same name are found, applied to different types
    of objects, the wrong CF may be returned.  It may even contain an
    invalid ContextObject.
    
    Allow LoadByName to take an optional LookupType value, or set of values.
    Additionally, infer this set if a ContextObject has been set, and limit
    appropriately.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 3603819..8e75eb3 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -405,6 +405,7 @@ sub LoadByName {
     my %args = (
         Queue => undef,
         Name  => undef,
+        LookupType => undef,
         @_,
     );
 
@@ -428,6 +429,20 @@ sub LoadByName {
     $CFs->SetContextObject( $self->ContextObject );
     my $field = $args{'Name'} =~ /\D/? 'Name' : 'id';
     $CFs->Limit( FIELD => $field, VALUE => $args{'Name'}, CASESENSITIVE => 0);
+
+    # The context object may be a ticket, for example, as context for a
+    # queue CF.  The valid lookup types are thus the entire set of
+    # ACLEquivalenceObjects for the context object.
+    $args{LookupType} ||= [
+        map {$_->CustomFieldLookupType}
+            ($self->ContextObject, $self->ContextObject->ACLEquivalenceObjects) ]
+        if $self->ContextObject;
+
+    $args{LookupType} = [ $args{LookupType} ]
+        if $args{LookupType} and not ref($args{LookupType});
+    $CFs->Limit( FIELD => "LookupType", OPERATOR => "IN", VALUE => $args{LookupType} )
+        if $args{LookupType};
+
     # Don't limit to queue if queue is 0.  Trying to do so breaks
     # RT::Group type CFs.
     if ( defined $args{'Queue'} ) {

commit 201b964ff69e8de48bcd60369346d2eef5fec0a3
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Jul 2 12:33:07 2013 -0400

    Allow specification of the LookupType of the CF to assign rights to
    
    This is useful when there are multiple CFs with the same name applied to
    different types of objects.

diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index ef5fb20..4a79aee 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -304,6 +304,7 @@ granted.  This is B<different> than the user/group/role receiving the right.
 =item Granted on a custom field by name (or ID), potentially a global or queue
 
     CF => 'Name',
+    LookupType => 'RT::User',  # optional, in case you need to disambiguate
 
 =item Granted on a queue
 
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 46df34c..81f1b6e 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -971,6 +971,7 @@ sub InsertData {
             if ( $item->{'CF'} ) {
                 $object = RT::CustomField->new( RT->SystemUser );
                 my @columns = ( Name => $item->{'CF'} );
+                push @columns, LookupType => $item->{'LookupType'} if $item->{'LookupType'};
                 push @columns, Queue => $item->{'Queue'} if $item->{'Queue'} and not ref $item->{'Queue'};
                 my ($ok, $msg) = $object->LoadByName( @columns );
                 unless ( $ok ) {

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


More information about the Rt-commit mailing list