added a descendants option to the high work org retrieval function
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 5 Feb 2008 15:25:14 +0000 (15:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 5 Feb 2008 15:25:14 +0000 (15:25 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8635 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm

index bc43965..ae19436 100644 (file)
@@ -1328,17 +1328,18 @@ __PACKAGE__->register_method(
             check is implied by the authtoken. /,
         params => [
                    {desc => 'authtoken', type => 'string'},
-            {desc => 'permission name', type => 'string'}
+            {desc => 'permission name', type => 'string'},
+            {desc => 'options hash, including "descendants", which will include all child orgs of the found perm orgs', type => 'hash'}
         ],
         return => {desc => 'An array of org IDs'}
     }
 );
 
 sub check_user_work_perms {
-    my($self, $conn, $auth, $perm) = @_;
+    my($self, $conn, $auth, $perm, $options) = @_;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
-    return $U->find_highest_work_orgs($e, $perm);
+    return $U->find_highest_work_orgs($e, $perm, $options);
 }
 
 __PACKAGE__->register_method(
index c91d6f4..be346a7 100644 (file)
@@ -1288,7 +1288,7 @@ sub find_highest_perm_org {
 
 
 sub find_highest_work_orgs {
-    my($self, $e, $perm) = @_;
+    my($self, $e, $perm, $options) = @_;
     my $work_orgs = $self->get_user_work_ou_ids($e, $e->requestor->id);
     $logger->debug("found work orgs @$work_orgs");
 
@@ -1320,14 +1320,20 @@ sub find_highest_work_orgs {
         $logger->debug("work org looking at $org");
                my $org_list = $self->get_org_full_path($org, $org_depth);
 
+               my $found = 0;
         for my $sub_org (@$org_list) {
-            $logger->debug("work org looking at sub-org $sub_org");
-            my $org_unit = $self->find_org($org_tree, $sub_org);
-            my ($ou_type) = grep { $_->id == $org_unit->ou_type } @$org_types;
-            if($ou_type->depth >= $org_depth) {
-                push(@allowed_orgs, $sub_org);
-                last;
-            }
+                       if(not $found) {
+                               $logger->debug("work org looking at sub-org $sub_org");
+                               my $org_unit = $self->find_org($org_tree, $sub_org);
+                               my ($ou_type) = grep { $_->id == $org_unit->ou_type } @$org_types;
+                               if($ou_type->depth >= $org_depth) {
+                                       push(@allowed_orgs, $sub_org);
+                                       $found = 1;
+                               }
+                       } else {
+                               last unless $$options{descendants}; 
+                               push(@allowed_orgs, $sub_org);
+                       }
         }
     }