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

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

index 24476e5..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(
@@ -2652,7 +2653,7 @@ __PACKAGE__->register_method(
        method => 'usrname_exists',
        api_name        => 'open-ils.actor.username.exists',
        signature => q/
-               Returns the user ID of the requested username if that username exists, returns null otherwise
+               Returns 1 if the requested username exists, returns 0 otherwise
        /
 );
 
@@ -2664,14 +2665,14 @@ sub usrname_exists {
        return $e->event unless $e->checkauth;
        my $a = $e->search_actor_user({usrname => $usrname, deleted=>'f'}, {idlist=>1});
        return $$a[0] if $a and @$a;
-       return undef;
+       return 0;
 }
 
 __PACKAGE__->register_method(
        method => 'barcode_exists',
        api_name        => 'open-ils.actor.barcode.exists',
        signature => q/
-               Returns the user ID for the requested barcode if that barcode exists, returns null otherwise
+               Returns 1 if the requested barcode exists, returns 0 otherwise
        /
 );
 
@@ -2680,8 +2681,8 @@ sub barcode_exists {
        my $e = new_editor(authtoken=>$auth);
        return $e->event unless $e->checkauth;
        my $card = $e->search_actor_card({barcode => $barcode});
-       return undef unless @$card;
-       return $card->[0]->usr;
+    return 0 unless @$card;
+    return $card->[0]->usr;
 }
 
 
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);
+                       }
         }
     }