[Rt-commit] [svn] r1982 - in rt/branches/3.3-TESTING: . lib/RT lib/t sbin

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Fri Dec 10 00:19:37 EST 2004


Author: jesse
Date: Fri Dec 10 00:19:36 2004
New Revision: 1982

Modified:
   rt/branches/3.3-TESTING/   (props changed)
   rt/branches/3.3-TESTING/configure.ac
   rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
   rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValue_Overlay.pm
   rt/branches/3.3-TESTING/lib/RT/Record.pm
   rt/branches/3.3-TESTING/lib/t/02regression.t.in
   rt/branches/3.3-TESTING/sbin/rt-test-dependencies.in
Log:
 r1998 at hualien:  jesse | 2004-12-10T05:18:47.952532Z
 Ruslan handed us a suite of tests. Some of those tests failed, demonstrating a couple of API issues with CustomFields.
 
 This led to more API bulletproofing and a SearchBuilder bump
 
 
 


Modified: rt/branches/3.3-TESTING/configure.ac
==============================================================================
--- rt/branches/3.3-TESTING/configure.ac	(original)
+++ rt/branches/3.3-TESTING/configure.ac	Fri Dec 10 00:19:36 2004
@@ -250,6 +250,7 @@
 		 lib/t/06mailgateway.pl
 		 lib/t/07acl.pl
 		 lib/t/08web_cf.pl
+		 lib/t/09record_customfields.t
  		 bin/mason_handler.fcgi
  		 bin/mason_handler.scgi
  		 bin/standalone_httpd

Modified: rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm	Fri Dec 10 00:19:36 2004
@@ -439,7 +439,7 @@
 
     my $ticket = RT::Ticket->new($self->CurrentUser);
     $ticket->Load($args{'Ticket'});
-    return($self->AddValueForObjecT(Content => $args{'Content'}, Object => $ticket));
+    return($self->AddValueForObject(Content => $args{'Content'}, Object => $ticket, at _));
 
 }
 
@@ -465,7 +465,7 @@
 
     my $ticket = RT::Ticket->new($self->CurrentUser);
     $ticket->load($args{'Ticket'});
-    return ($self->DeleteValueForObject(Object => $ticket, Content => $args{'Content'}));
+    return ($self->DeleteValueForObject(Object => $ticket, Content => $args{'Content'}, @_));
 
 }
 
@@ -946,6 +946,7 @@
                  Id => undef,
 		     @_ );
 
+
     unless ($self->CurrentUserHasRight('ModifyObjectCustomFieldValues')) {
         return (0, $self->loc('Permission Denied'));
     }
@@ -955,14 +956,15 @@
     if (my $id = $args{'Id'}) {
 	$oldval->Load($id);
     }
-    else {
+    unless ($oldval->id) { 
 	$oldval->LoadByObjectContentAndCustomField(
 	    Object => $args{'Object'}, 
 	    Content =>  $args{'Content'}, 
-	    CustomField => $self->Id
+	    CustomField => $self->Id,
 	);
     }
 
+
     # check ot make sure we found it
     unless ($oldval->Id) {
         return(0, $self->loc("Custom field value [_1] could not be found for custom field [_2]", $args{'Content'}, $self->Name));
@@ -995,6 +997,7 @@
 	
 	
 	$values->LimitToCustomField($self->Id);
+	$values->LimitToEnabled();
     $values->LimitToObject($object);
 
 	return ($values);

Modified: rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValue_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValue_Overlay.pm	(original)
+++ rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValue_Overlay.pm	Fri Dec 10 00:19:36 2004
@@ -109,7 +109,9 @@
     $self->LoadByCols( Content => $args{'Content'},
                          CustomField => $args{'CustomField'},
                          ObjectType => 'RT::Ticket',
-                         ObjectId => $args{'Ticket'},);
+                         ObjectId => $args{'Ticket'},
+			 Disabled => 0
+			 );
 
     
 }
@@ -127,9 +129,10 @@
     $self->LoadByCols( Content => $args{'Content'},
                          CustomField => $args{'CustomField'},
                          ObjectType => ref($obj),
-                         ObjectId => $obj->Id,);
+                         ObjectId => $obj->Id,
+			 Disabled => 0
+			 );
 
-    
 }
 
 sub Delete {

Modified: rt/branches/3.3-TESTING/lib/RT/Record.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Record.pm	(original)
+++ rt/branches/3.3-TESTING/lib/RT/Record.pm	Fri Dec 10 00:19:36 2004
@@ -1483,21 +1483,19 @@
 
 sub AddCustomFieldValue {
     my $self = shift;
-#    unless ( $self->CurrentUserHasRight('ModifyTicket') ) {
-#        return ( 0, $self->loc("Permission Denied") );
-#    }
     $self->_AddCustomFieldValue(@_);
 }
 
 sub _AddCustomFieldValue {
     my $self = shift;
     my %args = (
-        Field => undef,
-        Value => undef,
-	RecordTransaction => 1,
+        Field             => undef,
+        Value             => undef,
+        RecordTransaction => 1,
         @_
     );
 
+   # {{{ Get a custom field object from the 'Field' parameter.
     my $cf = RT::CustomField->new( $self->CurrentUser );
     if ( UNIVERSAL::isa( $args{'Field'}, "RT::CustomField" ) ) {
         $cf->Load( $args{'Field'}->id );
@@ -1507,17 +1505,24 @@
     }
 
     unless ( $cf->Id ) {
-        return ( 0, $self->loc("Custom field [_1] not found", $args{'Field'}) );
+        return ( 0,
+            $self->loc( "Custom field [_1] not found", $args{'Field'} ) );
     }
 
     my $OCFs = $self->CustomFields;
     $OCFs->Limit( FIELD => 'id', VALUE => $cf->Id );
-    unless ($OCFs->Count) {
-        return ( 0, $self->loc("Custom field [_1] does not apply to this object", $args{'Field'}) );
+    unless ( $OCFs->Count ) {
+        return (
+            0,
+            $self->loc(
+                "Custom field [_1] does not apply to this object",
+                $args{'Field'}
+            )
+        );
     }
-
-    # Load up a ObjectCustomFieldValues object for this custom field and this ticket
-    my $values = $cf->ValuesForObject( $self );
+    # }}}
+# Load up a ObjectCustomFieldValues object for this custom field and this ticket
+    my $values = $cf->ValuesForObject($self);
 
     unless ( $cf->ValidateValue( $args{'Value'} ) ) {
         return ( 0, $self->loc("Invalid value for custom field") );
@@ -1527,9 +1532,9 @@
     # value and record a "changed from foo to bar" transaction
     if ( $cf->SingleValue ) {
 
-        # We need to whack any old values here.  In most cases, the custom field should
-        # only have one value to delete.  In the pathalogical case, this custom field
-        # used to be a multiple and we have many values to whack....
+ # We need to whack any old values here.  In most cases, the custom field should
+ # only have one value to delete.  In the pathalogical case, this custom field
+ # used to be a multiple and we have many values to whack....
         my $cf_values = $values->Count;
 
         if ( $cf_values > 1 ) {
@@ -1538,97 +1543,120 @@
             while ( my $value = $values->Next ) {
                 $i++;
                 if ( $i < $cf_values ) {
-                    my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $value->Content);
+                    my ( $val, $msg ) = $cf->DeleteValueForObject(
+                        Object  => $self,
+                        Content => $value->Content
+                    );
                     unless ($val) {
-                        return (0,$msg);
+                        return ( 0, $msg );
                     }
                     my ( $TransactionId, $Msg, $TransactionObj ) =
                       $self->_NewTransaction(
-                        Type     => 'CustomField',
-                        Field    => $cf->Id,
+                        Type         => 'CustomField',
+                        Field        => $cf->Id,
                         OldReference => $value,
                       );
                 }
             }
         }
 
-        my ($old_value, $old_content);
-        if ($old_value = $cf->ValuesForObject( $self )->First) {
-	    $old_content = $old_value->Content();
-	    return (1) if $old_content eq $args{'Value'};
-	}
+        my ( $old_value, $old_content );
+        if ( $old_value = $cf->ValuesForObject($self)->First ) {
+            $old_content = $old_value->Content();
+            return (1) if( $old_content eq $args{'Value'} && $old_value->LargeContent eq $args{'LargeContent'});;
+        }
 
         my ( $new_value_id, $value_msg ) = $cf->AddValueForObject(
-            Object  => $self,
-            Content => $args{'Value'},
+            Object       => $self,
+            Content      => $args{'Value'},
             LargeContent => $args{'LargeContent'},
-            ContentType => $args{'ContentType'},
+            ContentType  => $args{'ContentType'},
         );
 
         unless ($new_value_id) {
-            return ( 0,
-                $self->loc("Could not add new custom field value. [_1] ",
-                  ,$value_msg) );
+            return (
+                0,
+                $self->loc(
+                    "Could not add new custom field value. [_1] ",,
+                    $value_msg
+                )
+            );
         }
 
         my $new_value = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
         $new_value->Load($new_value_id);
 
         # now that adding the new value was successful, delete the old one
-	if ($old_value) {
-	    my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $old_content);
-	    unless ($val) { 
-	    		return (0,$msg);
-	    }
-	}
-
-	if ($args{'RecordTransaction'}) {
-        my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
-            Type     => 'CustomField',
-            Field    => $cf->Id,
-            OldReference => $old_value,
-            NewReference => $new_value,
-        );
-	}
+        if ($old_value) {
+            my ( $val, $msg ) = $old_value->Delete();
+            unless ($val) {
+                return ( 0, $msg );
+            }
+        }
+
+        if ( $args{'RecordTransaction'} ) {
+            my ( $TransactionId, $Msg, $TransactionObj ) =
+              $self->_NewTransaction(
+                Type         => 'CustomField',
+                Field        => $cf->Id,
+                OldReference => $old_value,
+                NewReference => $new_value,
+              );
+        }
 
         if ( $old_value eq '' ) {
-            return ( 1, $self->loc("[_1] [_2] added", $cf->Name, $new_value->Content) );
+            return ( 1,
+                $self->loc( "[_1] [_2] added", $cf->Name, $new_value->Content )
+            );
         }
         elsif ( $new_value->Content eq '' ) {
-            return ( 1, $self->loc("[_1] [_2] deleted", $cf->Name, $old_content) );
+            return ( 1,
+                $self->loc( "[_1] [_2] deleted", $cf->Name, $old_value->Content ) );
         }
         else {
-            return ( 1, $self->loc("[_1] [_2] changed to [_3]", $cf->Name, $old_content, $new_value->Content ) );
+            return (
+                1,
+                $self->loc(
+                    "[_1] [_2] changed to [_3]", $cf->Name,
+                    $old_content,                $new_value->Content
+                )
+            );
         }
 
     }
 
     # otherwise, just add a new value and record "new value added"
     else {
-        my ( $new_value_id ) = $cf->AddValueForObject(
-            Object  => $self,
-            Content => $args{'Value'},
+        my ($new_value_id) = $cf->AddValueForObject(
+            Object       => $self,
+            Content      => $args{'Value'},
             LargeContent => $args{'LargeContent'},
-            ContentType => $args{'ContentType'},
+            ContentType  => $args{'ContentType'},
         );
 
         unless ($new_value_id) {
-            return ( 0,
-                $self->loc("Could not add new custom field value. "));
+            return ( 0, $self->loc("Could not add new custom field value. ") );
         }
-    if ( $args{'RecordTransaction'} ) {
-        my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
-            Type     => 'CustomField',
-            Field    => $cf->Id,
-            NewReference => $new_value_id,
-	    ReferenceType => 'RT::ObjectCustomFieldValue',
-        );
-        unless ($TransactionId) {
-            return ( 0,
-                $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
+        if ( $args{'RecordTransaction'} ) {
+            my ( $TransactionId, $Msg, $TransactionObj ) =
+              $self->_NewTransaction(
+                Type          => 'CustomField',
+                Field         => $cf->Id,
+                NewReference  => $new_value_id,
+                ReferenceType => 'RT::ObjectCustomFieldValue',
+              );
+            unless ($TransactionId) {
+                return ( 0,
+                    $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
+            }
         }
-    }
-        return ( 1, $self->loc("[_1] added as a value for [_2]",$args{'Value'}, $cf->Name));
+        return (
+            1,
+            $self->loc(
+                "[_1] added as a value for [_2]",
+                $args{'Value'}, $cf->Name
+            )
+        );
     }
 
 }
@@ -1651,15 +1679,12 @@
 sub DeleteCustomFieldValue {
     my $self = shift;
     my %args = (
-        Field => undef,
-        Value => undef,
-	ValueId => undef,
-        @_);
-
-#    XXX - normalise CF related ACLs... ask obra!
-#    unless ( $self->CurrentUserHasRight('ModifyTicket') ) {
-#        return ( 0, $self->loc("Permission Denied") );
-#    }
+        Field   => undef,
+        Value   => undef,
+        ValueId => undef,
+        @_
+    );
+
     my $cf = RT::CustomField->new( $self->CurrentUser );
     if ( UNIVERSAL::isa( $args{'Field'}, "RT::CustomField" ) ) {
         $cf->LoadById( $args{'Field'}->id );
@@ -1672,26 +1697,31 @@
         return ( 0, $self->loc("Custom field not found") );
     }
 
+    my ( $val, $msg ) = $cf->DeleteValueForObject(
+        Object  => $self,
+        Id      => $args{'ValueId'},
+        Content => $args{'Value'},
+    );
+    unless ($val) {
+        return ( 0, $msg );
+    }
+    my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
+        Type          => 'CustomField',
+        Field         => $cf->Id,
+        OldReference  => $val,
+        ReferenceType => 'RT::ObjectCustomFieldValue',
+    );
+    unless ($TransactionId) {
+        return ( 0, $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
+    }
 
-     my ($val, $msg) = $cf->DeleteValueForObject(
-	 Object => $self,
-	 Id => $args{'ValueId'},
-	 Content => $args{'Value'},
-     );
-     unless ($val) { 
-            return (0,$msg);
-     }
-        my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
-            Type     => 'CustomField',
-            Field    => $cf->Id,
-            OldReference => $val,
-	    ReferenceType => 'RT::ObjectCustomFieldValue',
-        );
-        unless($TransactionId) {
-            return(0, $self->loc("Couldn't create a transaction: [_1]", $Msg));
-        } 
-
-        return($TransactionId, $self->loc("[_1] is no longer a value for custom field [_2]", $TransactionObj->OldValue, $cf->Name));
+    return (
+        $TransactionId,
+        $self->loc(
+            "[_1] is no longer a value for custom field [_2]",
+            $TransactionObj->OldValue, $cf->Name
+        )
+    );
 }
 
 # }}}
@@ -1764,7 +1794,6 @@
     $cf_values->LimitToObject($self);
     $cf_values->OrderBy( FIELD => 'id', ORDER => 'ASC' );
 
-
     return ($cf_values);
 }
 

Modified: rt/branches/3.3-TESTING/lib/t/02regression.t.in
==============================================================================
--- rt/branches/3.3-TESTING/lib/t/02regression.t.in	(original)
+++ rt/branches/3.3-TESTING/lib/t/02regression.t.in	Fri Dec 10 00:19:36 2004
@@ -48,4 +48,4 @@
 require "@RT_LIB_PATH@/t/06mailgateway.pl";
 require "@RT_LIB_PATH@/t/07acl.pl";
 require "@RT_LIB_PATH@/t/08web_cf.pl";
-
+require "@RT_LIB_PATH@/t/09record_customfields.t";

Modified: rt/branches/3.3-TESTING/sbin/rt-test-dependencies.in
==============================================================================
--- rt/branches/3.3-TESTING/sbin/rt-test-dependencies.in	(original)
+++ rt/branches/3.3-TESTING/sbin/rt-test-dependencies.in	Fri Dec 10 00:19:36 2004
@@ -122,7 +122,7 @@
 DBI 1.37
 Test::Inline
 Class::ReturnValue 0.40
-DBIx::SearchBuilder 1.12
+DBIx::SearchBuilder 1.16
 Text::Template
 File::Spec 0.8
 HTML::Entities 


More information about the Rt-commit mailing list