From 29adcb54b971269410d4d1192292a14b136e8814 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 7 Dec 2005 23:13:46 +0000 Subject: [PATCH] added method to retrieve fleshed bucket by id added method to retrieve all buckets for a given user git-svn-id: svn://svn.open-ils.org/ILS/trunk@2277 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Actor/Container.pm | 79 +++++++++++++++++++ .../perlmods/OpenILS/Application/AppUtils.pm | 17 +++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm index fd58dc6f66..caceb1564e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm @@ -12,6 +12,7 @@ my $logger = "OpenSRF::Utils::Logger"; sub initialize { return 1; } +=head comment __PACKAGE__->register_method( method => "bucket_retrieve", api_name => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name", @@ -92,8 +93,86 @@ sub bucket_retrieve { return $resp if ($self->api_name =~ /fleshed/); return $buckets; } +=cut +my $svc = 'open-ils.storage'; +my $meth = 'open-ils.storage.direct.container'; +my $bibmeth = "$meth.biblio_record_entry_bucket"; +my $cnmeth = "$meth.call_number_bucket"; +my $copymeth = "$meth.copy_bucket"; +my $usermeth = "$meth.user_bucket"; + +__PACKAGE__->register_method( + method => "bucket_retrieve_all", + api_name => "open-ils.actor.container.bucket.all.retrieve_by_user", + notes => <<" NOTES"); + Retrieves all un-fleshed buckets assigned to given user + PARAMS(authtoken, bucketOwnerId) + If requestor ID is different than bucketOwnerId, requestor must have + VIEW_CONTAINER permissions. + NOTES + +sub bucket_retrieve_all { + my($self, $client, $authtoken, $userid) = @_; + + my ($staff, $user, $perm) = + $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER'); + return $perm if $perm; + + $logger->activity("User " . $staff->id . " retrieving buckets for user $user"); + + my %buckets; + + $buckets{biblio} = $apputils->simplereq( $svc, "$bibmeth.search.owner.atomic", $user ); + $buckets{callnumber} = $apputils->simplereq( $svc, "$cnmeth.search.owner.atomic", $user ); + $buckets{copy} = $apputils->simplereq( $svc, "$copymeth.search.owner.atomic", $user ); + $buckets{user} = $apputils->simplereq( $svc, "$usermeth.search.owner.atomic", $user ); + + return \%buckets; +} + +__PACKAGE__->register_method( + method => "bucket_flesh", + api_name => "open-ils.actor.container.bucket.flesh", + notes => <<" NOTES"); + Fleshes a bucket by id + PARAMS(authtoken, bucketId, bucketype) + Types include biblio, callnumber, copy, and user + If requestor ID is different than bucketOwnerId, requestor must have + VIEW_CONTAINER permissions. + NOTES + +sub bucket_flesh { + + my($self, $client, $authtoken, $bucket, $type) = @_; + + my( $staff, $evt ) = $apputils->check_ses($authtoken); + return $evt if $evt; + + my $meth = $bibmeth; + $meth = $cnmeth if $type eq "callnumber"; + $meth = $copymeth if $type eq "copy"; + $meth = $usermeth if $type eq "user"; + + my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket ); + if(!$bkt) {return undef}; + + $logger->debug("Fetching fleshed bucket $bucket"); + + if( $bkt->owner ne $staff->id ) { + my $userobj = $apputils->fetch_user($bkt->owner); + my $perm = $apputils->check_perms( + $staff->id, $userobj->home_ou, 'VIEW_CONTAINER' ); + return $perm if $perm; + } + + $bkt->items( $apputils->simplereq( $svc, + "$meth"."_item.search.bucket.atomic", $bucket ) ); + + return $bkt; +} + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index d3a0a0f287..bd81dab1fe 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -4,6 +4,8 @@ use base qw/OpenSRF::Application/; use OpenSRF::Utils::Cache; use OpenSRF::EX qw(:try); use OpenILS::Perm; +use OpenSRF::Utils::Logger; +my $logger = "OpenSRF::Utils::Logger"; my $cache_client = "OpenSRF::Utils::Cache"; @@ -112,6 +114,19 @@ sub rollback_db_session { # Checks to see if a user is logged in. Returns the user record on success, # throws an exception on error. # --------------------------------------------------------------------------- +sub check_ses { + my( $self, $session ) = @_; + my $user; + my $evt; + try { + $user = $self->check_user_session($session); + } catch Error with { + $evt = OpenILS::Event->new('NO_SESSION'); + }; + + return ( $user, $evt ); +} + sub check_user_session { my( $self, $user_session ) = @_; @@ -137,8 +152,6 @@ sub check_user_session { $session->kill_me(); return $user; - - } # generic simple request returning a scalar value -- 2.43.2