[Jifty-commit] r3910 - in apps/CASPlus/trunk: lib/CASPlus t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Aug 16 12:47:57 EDT 2007


Author: sterling
Date: Thu Aug 16 12:47:56 2007
New Revision: 3910

Modified:
   apps/CASPlus/trunk/   (props changed)
   apps/CASPlus/trunk/lib/CASPlus/CurrentUser.pm
   apps/CASPlus/trunk/t/40-is_mine.t

Log:
 r8691 at dynpc145:  andrew | 2007-08-16 11:47:04 -0500
 Added a test for and an initial attempt at making transitive ownership work.


Modified: apps/CASPlus/trunk/lib/CASPlus/CurrentUser.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/CurrentUser.pm	(original)
+++ apps/CASPlus/trunk/lib/CASPlus/CurrentUser.pm	Thu Aug 16 12:47:56 2007
@@ -175,11 +175,18 @@
         value  => 1,
     );
 
+    # TODO FIXME XXX Is using ->as_superuser() here and later the right way to
+    # get around the access controls or should I patch children_of() to do that
+    # more brutally? I.e., I think this may cause some infinite recursion when
+    # evaluating whether or not a particular user owns a thing while trying to
+    # evaluate profile permissions. More testing is needed. -- Sterling
+
     # Iterate through the relationships and fill the queue
     my @profile_queue;
     while (my $relationship = $relationships->next) {
         push @profile_queue, 
-            map { [ $_, 1 ] } $relationship->children_of($profile);
+            map { [ $_, 1 ] } 
+                $relationship->children_of($profile->as_superuser);
     }
 
     # Preload the maximum depth
@@ -211,7 +218,7 @@
         while (my $relationship = $relationships->next) {
             push @profile_queue, 
                 map { [ $_, $current_depth + 1 ] } 
-                    $relationship->children_of($current_object);
+                    $relationship->children_of($current_object->as_superuser);
         }
     }
 

Modified: apps/CASPlus/trunk/t/40-is_mine.t
==============================================================================
--- apps/CASPlus/trunk/t/40-is_mine.t	(original)
+++ apps/CASPlus/trunk/t/40-is_mine.t	Thu Aug 16 12:47:56 2007
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Jifty::Test tests => 12;
+use Jifty::Test tests => 19;
 
 # Grab a system user
 my $system_user = CASPlus::CurrentUser->superuser;
@@ -19,7 +19,7 @@
 # Create a test user
 my $user = CASPlus::Model::User->new(current_user => $system_user);
 $user->create(
-    username => 'test123',
+    username => 'Charles Montgomery Burns',
     password => 'test123',
 );
 ok($user->id, 'Created a user');
@@ -84,3 +84,56 @@
 $address->load($address_id);
 ok($address->id, 'Reloaded the test address');
 is($current_user->is_my($address), 1, 'it is_my address!');
+
+# Next phase: Create a grandchild object, it also MUST BE MINE!!! Muahahahahaha
+
+# Create relationship between employees and addresses
+$relationship->create(
+    name                    => 'Manager',
+    parent_name             => 'Supervisor',
+    child_name              => 'Supervisees',
+    relation_parent         => $employee_profile,
+    relation_child          => $employee_profile,
+    many_parents            => 0,
+    many_children           => 1,
+    parents_own_children    => 1,
+    ownership_is_transitive => 1,
+);
+ok($relationship->id, 'Created an employee-employee relationship');
+
+# Create a supervised employee
+$user = CASPlus::Model::User->new(current_user => $system_user);
+$user->create(
+    username => 'Waylon Smithers',
+    password => 'test123',
+);
+ok($user->id, 'Created a user');
+
+# Create a supervised employee
+my $employee2 = $employee_profile->record_class->new(current_user => $system_user);
+$employee2->create(
+    user_object => $user,
+    supervisor  => $employee,
+);
+ok($employee2->id, 'created an employee to test with');
+
+# Create a supervised employee
+$user->create(
+    username => 'Homer Simpson',
+    password => 'test123',
+);
+ok($user->id, 'Created a user');
+
+# Create a supervised employee
+my $employee3 = $employee_profile->record_class->new(current_user => $system_user);
+$employee3->create(
+    user_object => $user,
+    supervisor  => $employee2,
+);
+ok($employee3->id, 'created an employee to test with');
+
+# Another test of parents_own_children
+is($current_user->is_my($employee2), 1, 'it is_my employee!');
+
+# A test of ownership_is_transitive
+is($current_user->is_my($employee3), 1, 'it is_my employee again!');


More information about the Jifty-commit mailing list