org_unit_list and org_id_list now return sub-lists, segregated by branches of the...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Apr 2008 18:29:18 +0000 (18:29 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Apr 2008 18:29:18 +0000 (18:29 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9348 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index e00553c..f74edd5 100644 (file)
@@ -1327,8 +1327,12 @@ __PACKAGE__->register_method(
     authoritative => 1,
     signature => q/
         @see open-ils.actor.user.work_perm.highest_org_set
-        Returns a flat list of all of the org_units where the user
-        has the requested permission.
+        Returns a list of list of all of the org_units where the user
+        has the requested permission.  The first item in each list
+        is the highest permission org for that section of the
+        org tree.  The remaining items in each sub-list are the 
+        descendants of that org.
+
     /
 );
 
@@ -1338,8 +1342,11 @@ __PACKAGE__->register_method(
     authoritative => 1,
     signature => q/
         @see open-ils.actor.user.work_perm.highest_org_set
-        Returns a flat list of all of the org_units where the user
-        has the requested permission.
+        Returns a list of lists of all of the org_unit IDs where the user
+        has the requested permission.  The first item in each list
+        is the highest permission org for that section of the
+        org tree.  The remaining items in each sub-list are the 
+        descendants of that org.
     /
 );
 
@@ -1349,17 +1356,24 @@ sub check_user_work_perms {
     return $e->event unless $e->checkauth;
     my $orglist = $U->find_highest_work_orgs($e, $perm, $options);
 
-    return $orglist if
-        $self->api_name =~ /highest_org_set/;
+    return $orglist if $self->api_name =~ /highest_org_set/;
 
     # build a list of org trees
     return get_org_descendants($self, $conn, $orglist)
         if $self->api_name =~ /org_tree_list/;
 
     my @list;
-    push(@list, @{$U->get_org_descendants($_)}) for @$orglist;
-    return \@list if $self->api_name =~ /org_id_list/;
-    return $e->batch_retrieve_actor_org_unit(\@list);
+    for my $orgid (@$orglist) {
+        my @sublist = grep {$_ ne $orgid} @{$U->get_org_descendants($orgid)};
+        unshift @sublist, $orgid; # make sure it's at the front of the list
+        if($self->api_name =~ /org_id_list/) {
+            push(@list, \@sublist);
+        } else {
+            push(@list, $e->batch_retrieve_actor_org_unit(\@sublist));
+        }
+    }
+
+    return \@list;
 }