added versions of work perm org fetcher to return flat list of all org units or org...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Apr 2008 17:38:34 +0000 (17:38 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Apr 2008 17:38:34 +0000 (17:38 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9344 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 5b711f3..7f39418 100644 (file)
@@ -1311,7 +1311,7 @@ __PACKAGE__->register_method(
 
 __PACKAGE__->register_method(
        method => 'check_user_work_perms',
-       api_name        => 'open-ils.actor.user.work_perm.highest_org_tree_set',
+       api_name        => 'open-ils.actor.user.work_perm.org_tree_list',
     authoritative => 1,
     signature => q/
         @see open-ils.actor.user.work_perm.highest_org_set
@@ -1321,13 +1321,45 @@ __PACKAGE__->register_method(
     /
 );
 
+__PACKAGE__->register_method(
+       method => 'check_user_work_perms',
+       api_name        => 'open-ils.actor.user.work_perm.org_unit_list',
+    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.
+    /
+);
+
+__PACKAGE__->register_method(
+       method => 'check_user_work_perms',
+       api_name        => 'open-ils.actor.user.work_perm.org_id_list',
+    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.
+    /
+);
+
 sub check_user_work_perms {
     my($self, $conn, $auth, $perm, $options) = @_;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
     my $orglist = $U->find_highest_work_orgs($e, $perm, $options);
-    return $orglist unless $self->api_name =~ /tree/;
-    return get_org_descendants($self, $conn, $orglist);
+
+    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_set/;
+
+    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);
 }
 
 
index b7aacf7..1404008 100644 (file)
@@ -1389,17 +1389,16 @@ sub get_org_tree {
 
 sub get_org_descendants {
        my($self, $org_id, $depth) = @_;
-       $depth ||= 0;
+
+       my $select = {
+               transform => 'actor.org_unit_descendants',
+               column => 'id',
+               result_field => 'id',
+       };
+       $select->{params} = [$depth] if defined $depth;
 
        my $org_list = OpenILS::Utils::CStoreEditor->new->json_query({
-               select => {
-                       aou => [{
-                               transform => 'actor.org_unit_descendants',
-                               column => 'id',
-                               result_field => 'id',
-                               params => [$depth]
-                       }],
-               },
+               select => {aou => [$select]},
         from => 'aou',
                where => {id => $org_id}
        });