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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Aug 16 11:02:11 EDT 2007


Author: sterling
Date: Thu Aug 16 11:02:08 2007
New Revision: 3909

Modified:
   apps/CASPlus/trunk/   (props changed)
   apps/CASPlus/trunk/Makefile.PL
   apps/CASPlus/trunk/lib/CASPlus/CurrentUser.pm
   apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm
   apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm
   apps/CASPlus/trunk/t/40-is_mine.t

Log:
 r8689 at dynpc145:  andrew | 2007-08-16 10:01:27 -0500
 Fixed the remaining broken TODO tests for is_my().


Modified: apps/CASPlus/trunk/Makefile.PL
==============================================================================
--- apps/CASPlus/trunk/Makefile.PL	(original)
+++ apps/CASPlus/trunk/Makefile.PL	Thu Aug 16 11:02:08 2007
@@ -30,4 +30,6 @@
 
 auto_install();
 
+tests 't/*.t';
+
 WriteAll;

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 11:02:08 2007
@@ -158,10 +158,11 @@
     return 0 if !$self->id;
 
     # Get the profile belonging to the current user
-    my $profile = $self->profile;
+    my $profile    = $self->profile;
+    my $profile_id = $profile->unique_id;
 
     # Check to see if the object is directly linked to the current user 
-    return 1 if $profile->unique_id == $object_id;
+    return 1 if $profile_id == $object_id;
 
     # Load the relationships for the current profile
     my $relationships = CASPlus::Model::ProfileRelationshipCollection->new;
@@ -178,7 +179,7 @@
     my @profile_queue;
     while (my $relationship = $relationships->next) {
         push @profile_queue, 
-            map { [ $_, 1 ] } $relationship->children_of($object);
+            map { [ $_, 1 ] } $relationship->children_of($profile);
     }
 
     # Preload the maximum depth
@@ -190,7 +191,7 @@
         my ($current_object, $current_depth) = @$current; 
 
         # Found it! It's mine!
-        return 1 if $current_object->unique_id = $object_id;
+        return 1 if $current_object->unique_id == $object_id;
 
         # At maximum depth, don't go deeper
         next if $current_depth >= $maximum_depth;
@@ -199,7 +200,7 @@
         $relationships->unlimit;
         $relationships->limit(
             column => 'relation_parent',
-            value  => $current_object->profile,
+            value  => $current_object->profile_definition,
         );
         $relationships->limit(
             column => 'ownership_is_transitive',

Modified: apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm	(original)
+++ apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm	Thu Aug 16 11:02:08 2007
@@ -236,7 +236,6 @@
 
 =cut
 
-# TODO Make this more sophisticated based upon roles and permissions.
 sub current_user_can {
     my ($self, $right, %args) = @_;
 

Modified: apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm	(original)
+++ apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm	Thu Aug 16 11:02:08 2007
@@ -544,6 +544,28 @@
     return @parents;
 }
 
+=head2 current_user_can
+
+This allows anyone to read. Users with a role granting the permission to manage profiles and superuser may perform any other operation.
+
+=cut
+
+sub current_user_can {
+    my ($self, $right, %args) = @_;
+
+    if ($right eq 'read') {
+        return 1;
+    }
+
+    else {
+        for my $role ($self->current_user->roles) {
+            return 1 if $role->may_manage_profiles;
+        }
+    }
+
+    return $self->SUPER::current_user_can($right, %args);
+}
+
 =head1 AUTHOR
 
 Andrew Sterling Hanenkamp, C<< <hanenkamp at cpan.org> >>

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 11:02:08 2007
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Jifty::Test tests => 11;
+use Jifty::Test tests => 12;
 
 # Grab a system user
 my $system_user = CASPlus::CurrentUser->superuser;
@@ -45,43 +45,42 @@
 ok($current_user->is_my($employee), 'is_my employee');
 
 # Next phase: Create a child object, it also MUST BE MINE!!! Muahahahahaha
-TODO: {
-    local $TODO = 'is_my is not yet defined for relationships';
 
-    # Create a address profile
-    my $address_profile = CASPlus::Model::Profile->new(current_user => $system_user);
-    $address_profile->create(
-        name         => 'Address',
-        profile_type => 'other',
-    );
-    ok($address_profile->id, 'Created an address profile');
-
-    # Create relationship between employees and addresses
-    my $relationship = CASPlus::Model::ProfileRelationship->new(current_user => $system_user);
-    $relationship->create(
-        name                   => 'Address',
-        parent_name            => 'Employee',
-        child_name             => 'Address',
-        relation_parent        => $employee_profile,
-        relation_child         => $address_profile,
-        many_parents           => 0,
-        many_children          => 0,
-        parents_own_children   => 1,
-        dependent_relationship => 1,
-    );
-    ok($relationship->id, 'Created an employee-address relationship');
-
-    # Create an address
-    my $address = $address_profile->record_class->new(current_user => $system_user);
-    $address->create(
-        employee => $employee,
-    );
-    my $address_id = $address->id;
-    ok($address->id, 'Created an address to test with');
-
-    # Reload it, IT MUST BE MINE!
-    $address = $address_profile->record_class->new;
-    $address->load($address_id);
-    ok($address->id, 'Reloaded the test address');
-    ok($current_user->is_my($address), 'it is_my address!');
-};
+# Create a address profile
+my $address_profile = CASPlus::Model::Profile->new(current_user => $system_user);
+$address_profile->create(
+    name         => 'Address',
+    profile_type => 'other',
+);
+ok($address_profile->id, 'Created an address profile');
+
+# Create relationship between employees and addresses
+my $relationship = CASPlus::Model::ProfileRelationship->new(current_user => $system_user);
+my $r_id = $relationship->create(
+    name                   => 'Address',
+    parent_name            => 'Employee',
+    child_name             => 'Address',
+    relation_parent        => $employee_profile,
+    relation_child         => $address_profile,
+    many_parents           => 0,
+    many_children          => 0,
+    parents_own_children   => 1,
+    dependent_relationship => 1,
+);
+ok($relationship->id, 'Created an employee-address relationship');
+$relationship->load($r_id);
+is($relationship->id, $r_id, 'Checked actual relationships creation');
+
+# Create an address
+my $address = $address_profile->record_class->new(current_user => $system_user);
+$address->create(
+    employee => $employee,
+);
+my $address_id = $address->id;
+ok($address->id, 'Created an address to test with');
+
+# Reload it, IT MUST BE MINE!
+$address = $address_profile->record_class->new;
+$address->load($address_id);
+ok($address->id, 'Reloaded the test address');
+is($current_user->is_my($address), 1, 'it is_my address!');


More information about the Jifty-commit mailing list