[Rt-commit] r8230 - rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Thu Jul 19 13:59:07 EDT 2007


Author: ruz
Date: Thu Jul 19 13:59:07 2007
New Revision: 8230

Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/ACE_Overlay.pm

Log:
* use 'can' to check that AvailableRights method is there and use it
* AvalaibleRights method of RT::System class grab everything we need
  from other objects, so we don't have to duplicate effort
  (especially when we do it wrong :))

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/ACE_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/ACE_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/ACE_Overlay.pm	Thu Jul 19 13:59:07 2007
@@ -262,30 +262,15 @@
     $args{'RightName'} = $canonic_name;
 
     #check if it's a valid RightName
-    if ( ref ($args{'Object'} eq 'RT::Queue'  )) {
+    if ( $args{'Object'}->can('AvailableRights') ) {
         unless ( exists $args{'Object'}->AvailableRights->{ $args{'RightName'} } ) {
-            $RT::Logger->warning("Couldn't validate right name". $args{'RightName'});
+            $RT::Logger->warning(
+                "Couldn't validate right name '$args{'RightName'}'"
+                ." for object of ". ref $args{'Object'} ." class"
+            );
             return ( 0, $self->loc('Invalid right') );
         }
     }
-    elsif ( ref ($args{'Object'} eq 'RT::Group'  )) {
-        unless ( exists $args{'Object'}->AvailableRights->{ $args{'RightName'} } ) {
-            $RT::Logger->warning("Couldn't validate group right name". $args{'RightName'});
-            return ( 0, $self->loc('Invalid right') );
-        }
-    }
-    elsif ( ref ($args{'Object'} eq 'RT::System'  )) {
-        my $q = RT::Queue->new($self->CurrentUser);
-        my $g = RT::Group->new($self->CurrentUser);
-
-        unless (( exists $g->AvailableRights->{ $args{'RightName'} } )
-        || ( exists $g->AvailableRights->{ $args{'RightName'} } )
-        || ( exists $RT::System->AvailableRights->{ $args{'RightName'} } ) ) {
-            $RT::Logger->warning("Couldn't validate system right name - ". $args{'RightName'});
-            return ( 0, $self->loc('Invalid right') );
-        }
-    }
-
     # }}}
 
     # Make sure the right doesn't already exist.
@@ -311,7 +296,7 @@
     #Clear the key cache. TODO someday we may want to just clear a little bit of the keycache space. 
     RT::Principal->InvalidateACLCache();
 
-    if ( $id > 0 ) {
+    if ( $id ) {
         return ( $id, $self->loc('Right Granted') );
     }
     else {


More information about the Rt-commit mailing list