From 4416294aaefe2328fe91d724709b8649f5fa8332 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 14 Apr 2008 17:38:34 +0000 Subject: [PATCH] added versions of work perm org fetcher to return flat list of all org units or org IDs. if no depth is provided to get_org_depth, do not default to 0 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 | 38 ++++++++++++++++++++-- .../src/perlmods/OpenILS/Application/AppUtils.pm | 17 +++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 5b711f3e64..7f39418fc3 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -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); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index b7aacf7c8a..1404008b0a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -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} }); -- 2.11.0