[Rt-commit] r3476 - in rt/branches/3.4-RELEASE: . lib/RT

kevinr at bestpractical.com kevinr at bestpractical.com
Thu Jul 14 18:22:40 EDT 2005


Author: kevinr
Date: Thu Jul 14 18:22:40 2005
New Revision: 3476

Modified:
   rt/branches/3.4-RELEASE/   (props changed)
   rt/branches/3.4-RELEASE/lib/RT/ACE_Overlay.pm
   rt/branches/3.4-RELEASE/lib/RT/Principal_Overlay.pm
Log:
 r6308 at SAD-GIRL-IN-SNOW:  kevinr | 2005-07-14 18:22:19 -0400
 * Applied Ruslan Zakirov's patch to fix the way ACE Object{,Type,Id} handles
 arguments


Modified: rt/branches/3.4-RELEASE/lib/RT/ACE_Overlay.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/ACE_Overlay.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/ACE_Overlay.pm	Thu Jul 14 18:22:40 2005
@@ -133,8 +133,8 @@
 
             OR
 
-        ObjectType => undef,
-        ObjectId => undef
+	      ObjectType => undef,
+	      ObjectId => undef
 
 =cut
 
@@ -159,16 +159,9 @@
         );
     }
 
-    my ($object_type, $object_id);
-    
-    if ($args{'Object'} && UNIVERSAL::can($args{'Object'},'id')) {
-        $object_type = ref($args{'Object'});
-        $object_id = $args{'Object'}->id;
-    } elsif ($args{'ObjectId'} || $args{'ObjectType'}) {
-        $object_type = $args{'ObjectType'};
-        $object_id = $args{'ObjectId'};
-    } else {
-            return ( 0, $self->loc("System error. Right not granted.") );
+    my ($object, $object_type, $object_id) = $self->_ParseObjectArg( %args );
+    unless( $object ) {
+	return ( 0, $self->loc("System error. Right not granted.") );
     }
 
     $self->LoadByCols( PrincipalId   => $princ_obj->Id,
@@ -225,8 +218,16 @@
     my %args = ( PrincipalId   => undef,
                  PrincipalType => undef,
                  RightName     => undef,
-                 Object    => $RT::System,
+                 Object        => undef,
                  @_ );
+    #if we haven't specified any sort of right, we're talking about a global right
+    if (!defined $args{'Object'} && !defined $args{'ObjectId'} && !defined $args{'ObjectType'}) {
+        $args{'Object'} = $RT::System;
+    }
+    ($args{'Object'}, $args{'ObjectType'}, $args{'ObjectId'}) = $self->_ParseObjectArg( %args );
+    unless( $args{'Object'} ) {
+	return ( 0, $self->loc("System error. Right not granted.") );
+    }
 
     # {{{ Validate the principal
     my $princ_obj;
@@ -242,16 +243,6 @@
 
     # }}}
 
-
-    if ($args{'Object'} && ($args{'ObjectId'} || $args{'ObjectType'})) {
-        $RT::Logger->crit("ACE::Create called with an ObjectType or an ObjectId");
-        return ( 0, $self->loc("System error. Right not granted.") );
-    }
-
-    unless ($args{'Object'} && UNIVERSAL::can($args{'Object'},'id')) {
-        $RT::Logger->crit("ACE::Create called with Object that has no id method");
-        return ( 0, $self->loc("System error. Right not granted.") );
-    }
     # {{{ Check the ACL
 
     if (ref( $args{'Object'}) eq 'RT::Group' ) {
@@ -307,8 +298,8 @@
     $self->LoadByCols( PrincipalId   => $princ_obj->id,
                        PrincipalType => $args{'PrincipalType'},
                        RightName     => $args{'RightName'},
-                       ObjectType    => ref($args{'Object'}),
-                       ObjectId      => $args{'Object'}->id,
+                       ObjectType    => $args{'ObjectType'},
+                       ObjectId      => $args{'ObjectId'},
                        DelegatedBy   => 0,
                        DelegatedFrom => 0 );
     if ( $self->Id ) {
@@ -936,5 +927,32 @@
     return ( $princ_obj, $princ_type );
 }
 
+sub _ParseObjectArg {
+    my $self = shift;
+    my %args = ( Object    => undef,
+                 ObjectId    => undef,
+                 ObjectType    => undef,
+                 @_ );
+
+    if( $args{'Object'} && ($args{'ObjectId'} || $args{'ObjectType'}) ) {
+	$RT::Logger->crit( "Method called with an ObjectType or an ObjectId and Object args" );
+	return ();
+    } elsif( $args{'Object'} && !UNIVERSAL::can($args{'Object'},'id') ) {
+	$RT::Logger->crit( "Method called called Object that has no id method" );
+	return ();
+    } elsif( $args{'Object'} ) {
+	my $obj = $args{'Object'};
+	return ($obj, ref $obj, $obj->id);
+    } elsif ( $args{'ObjectType'} ) {
+	my $obj =  $args{'ObjectType'}->new( $self->CurrentUser );
+	$obj->Load( $args{'ObjectId'} );
+	return ($obj, ref $obj, $obj->id);
+    } else {
+	$RT::Logger->crit( "Method called with wrong args" );
+	return ();
+    }
+}
+
+
 # }}}
 1;

Modified: rt/branches/3.4-RELEASE/lib/RT/Principal_Overlay.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Principal_Overlay.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Principal_Overlay.pm	Thu Jul 14 18:22:40 2005
@@ -157,11 +157,6 @@
                 @_);
 
 
-    #if we haven't specified any sort of right, we're talking about a global right
-    if (!defined $args{'Object'} && !defined $args{'ObjectId'} && !defined $args{'ObjectType'}) {
-        $args{'Object'} = $RT::System;
-    }
-
     unless ($args{'Right'}) {
         return(0, $self->loc("Invalid Right"));
     }


More information about the Rt-commit mailing list