From f37f8b6faad4323be7039a34a4b761b9182aa9a9 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 19 Jul 2005 17:49:37 +0000 Subject: [PATCH] adding more permissions and exceptions related to the additions of more accurate renewals processing git-svn-id: svn://svn.open-ils.org/ILS/trunk@1280 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Circ.pm | 18 ++- .../OpenILS/Application/Circ/Holds.pm | 78 +++++++++- .../OpenILS/Application/Circ/Rules.pm | 147 ++++++++---------- Open-ILS/src/perlmods/OpenILS/EX.pm | 1 + Open-ILS/src/templates/strings/ex.ttk | 3 + Open-ILS/src/templates/strings/perm.ttk | 1 + 6 files changed, 158 insertions(+), 90 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 329c2fdbe0..7c910c3a01 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -40,11 +40,20 @@ sub checkouts_by_user { if(!$user_id) { $user_id = $user_obj->id(); } +# my $circs = $session->request( +# "open-ils.storage.direct.action.circulation.search.atomic", +# { +# usr => $user_id, +# xact_finish => undef, +# stop_fines => [ undef, "MAXFINES", "LONGOVERDUE" ], +# }, +# { order_by => "due_date" } ); + my $circs = $session->request( - "open-ils.storage.direct.action.circulation.search.atomic", - { usr => $user_id, xact_finish => undef } ); + "open-ils.storage.direct.action.open_circulation.search.usr.atomic", $user_id ); $circs = $circs->gather(1); + my @results; for my $circ (@$circs) { @@ -61,11 +70,6 @@ sub checkouts_by_user { $copy = $copy->gather(1); $record = $record->gather(1); -# my $due_date = -# OpenSRF::Utils->interval_to_seconds( -# $circ->duration ) + int(time()); -# $circ->due_date($due_date); - use Data::Dumper; warn Dumper $circ; my $u = OpenILS::Utils::ModsParser->new(); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 6edd5a4c8e..f0f96f4bf6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -168,6 +168,7 @@ is the requestor and if the requestor is different from the user, then the requestor must have VIEW_HOLDS permissions. NOTE + sub retrieve_holds { my($self, $client, $login_session, $user_id) = @_; @@ -181,8 +182,9 @@ sub retrieve_holds { my $session = OpenSRF::AppSession->create("open-ils.storage"); my $req = $session->request( - "open-ils.storage.direct.action.hold_request.search.usr.atomic", - $user_id ); + "open-ils.storage.direct.action.hold_request.search.atomic", + "usr" => $user_id , { order_by => "request_time" }); + my $h = $req->gather(1); $session->disconnect(); return $h; @@ -196,6 +198,7 @@ __PACKAGE__->register_method( Cancels the specified hold. The login session is the requestor and if the requestor is different from the usr field on the hold, the requestor must have CANCEL_HOLDS permissions. + the hold may be either the hold object or the hold id NOTE sub cancel_hold { @@ -203,6 +206,13 @@ sub cancel_hold { my $user = $apputils->check_user_session($login_session); + my $session = OpenSRF::AppSession->create("open-ils.storage"); + + if(!ref($hold)) { + $hold = $session->request( + "open-ils.storage.direct.action.hold_request.retrieve", $hold)->gather(1); + } + if($user->id ne $hold->usr) { if($apputils->check_user_perms($user->id, $user->home_ou, "CANCEL_HOLDS")) { return OpenILS::Perm->new("CANCEL_HOLDS"); @@ -212,7 +222,6 @@ sub cancel_hold { use Data::Dumper; warn "Cancelling hold: " . Dumper($hold) . "\n"; - my $session = OpenSRF::AppSession->create("open-ils.storage"); my $req = $session->request( "open-ils.storage.direct.action.hold_request.delete", $hold ); @@ -258,6 +267,69 @@ sub update_hold { } +__PACKAGE__->register_method( + method => "retrieve_hold_status", + api_name => "open-ils.circ.hold.status.retrieve", + notes => <<" NOTE"); + Calculates the current status of the hold. + the requestor must have VIEW_HOLDS permissions if the hold is for a user + other than the requestor. + Returns -1 on error (for now) + Returns 1 for 'waiting for copy to become available' + Returns 2 for 'waiting for copy capture' + Returns 3 for 'in transit' + Returns 4 for 'arrived' + NOTE + +sub retrieve_hold_status { + my($self, $client, $login_session, $hold_id) = @_; + + my $user = $apputils->check_user_session($login_session); + + my $session = OpenSRF::AppSession->create("open-ils.storage"); + + my $hold = $session->request( + "open-ils.storage.direct.action.hold_request.retrieve", $hold_id )->gather(1); + return -1 unless $hold; # should be an exception + + + if($user->id ne $hold->usr) { + if($apputils->check_user_perms($user->id, $user->home_ou, "VIEW_HOLDS")) { + return OpenILS::Perm->new("VIEW_HOLDS"); + } + } + + return 1 unless (defined($hold->current_copy)); + + #return 2 unless (defined($hold->capture_time)); + + my $copy = $session->request( + "open-ils.storage.direct.asset.copy.retrieve", $hold->current_copy )->gather(1); + return 1 unless $copy; # should be an exception + + use Data::Dumper; + warn "Hold Copy in status check: " . Dumper($copy) . "\n\n"; + + return 4 if ($hold->capture_time and $copy->circ_lib eq $hold->pickup_lib); + + my $transit = _fetch_hold_transit($session, $hold->id); + return 4 if(ref($transit) and defined($transit->dest_recv_time) ); + + return 3 if defined($hold->capture_time); + + return 2; +} + + +sub _fetch_hold_transit { + my $session = shift; + my $holdid = shift; + return $session->request( + "open-ils.storage.direct.action.hold_transit_copy.search.hold", + $holdid )->gather(1); +} + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm index 555e78fed7..72062ebb2e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm @@ -426,7 +426,7 @@ sub circulate { $circ->due_date($due_date); if($isrenew) { - warn "Renewing circ...."; + warn "Renewing circ.... ".$circ->id ." and setting num renews to " . $numrenews - 1 . "\n"; $circ->renewal(1); $circ->clear_id; $circ->renewal_remaining($numrenews - 1); @@ -591,10 +591,17 @@ sub build_circ_object { } + __PACKAGE__->register_method( method => "checkin", api_name => "open-ils.circ.checkin.barcode", -); + notes => <<" NOTES"); + Checks in based on barcode + Returns record, status, text, circ, copy, route_to + 'status' values: + 0 = OK + 1 = 'copy required to fulfil a hold' + NOTES sub checkin { my( $self, $client, $user_session, $barcode, $isrenewal ) = @_; @@ -603,9 +610,12 @@ sub checkin { my $copy; my $circ; + my $transaction; + my $user = $apputils->check_user_session($user_session); + try { my $session = $apputils->start_db_session(); - + warn "retrieving copy for checkin\n"; if(!$shelving_locations) { @@ -621,36 +631,39 @@ sub checkin { $barcode ); $copy = $copy_req->gather(1)->[0]; if(!$copy) { - $client->respond_complete( - OpenILS::EX->new("UNKNOWN_BARCODE")->ex); + $client->respond_complete(OpenILS::EX->new("UNKNOWN_BARCODE")->ex); } + + $copy->status(0); # find circ's where the transaction is still open for the # given copy. should only be one. - warn "Retrieving circ for checking\n"; + warn "Retrieving circ for checkin\n"; my $circ_req = $session->request( "open-ils.storage.direct.action.circulation.search.atomic", { target_copy => $copy->id, xact_finish => undef } ); $circ = $circ_req->gather(1)->[0]; + if(!$circ) { $err = "No circulation exists for the given barcode"; } else { + + $transaction = $session->request( + "open-ils.storage.direct.money.billable_transaction_summary.retrieve", $circ->id)->gather(1); warn "Checking in circ ". $circ->id . "\n"; $circ->stop_fines("CHECKIN"); $circ->stop_fines("RENEW") if($isrenewal); - - $circ->xact_finish("now"); + $circ->xact_finish("now") if($transaction->balance_owed <= 0 ); my $cp_up = $session->request( - "open-ils.storage.direct.asset.copy.update", - $copy ); + "open-ils.storage.direct.asset.copy.update", $copy ); $cp_up->gather(1); my $ci_up = $session->request( @@ -669,10 +682,27 @@ sub checkin { }; if($err) { + return { record => undef, status => -1, text => $err }; } else { + my $status = "0"; + my $status_text = "OK"; + + # check to see if the copy is needed to fulfil a hold + my $r = $apputils->simple_scalar_request( + "open-ils.storage", + "open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic", + $copy->id ); + + if(@$r != 0) { + if( $user->id ne $circ->usr ) { + $status = "1"; + $status_text = "Copy needed to fulfill hold"; + } + } + my $record = $apputils->simple_scalar_request( "open-ils.storage", "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy", @@ -684,8 +714,8 @@ sub checkin { return { record => $mods, - status => 0, - text => "OK", + status => $status, + text => $status_text, circ => $circ, copy => $copy, route_to => $shelving_locations->{$copy->location} @@ -727,12 +757,31 @@ sub renew { my $user = $apputils->check_user_session($login_session); my $session = OpenSRF::AppSession->create("open-ils.storage"); + my $copy = _grab_copy_by_id($session, $circ->target_copy); + + my $r = $session->request( + "open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic", + $copy->id )->gather(1); + + if(@$r != 0) { + if( $user->id ne $circ->usr ) { + if($apputils->check_user_perms($user->id, $user->home_ou, "RENEW_HOLD_OVERRIDE")) { + return OpenILS::Perm->new("RENEW_HOLD_OVERRIDE"); + } + } + + return OpenILS::EX->new("COPY_NEEDED_FOR_HOLD")->ex; + } + if(!ref($circ)) { $circ = $session->request( "open-ils.storage.direct.action.circulation.retrieve", $circ )->gather(1); } + my $iid = $circ->id; + warn "Attempting to renew circ " . $iid . "\n"; + if($user->id ne $circ->usr) { if($apputils->check_user_perms($user->id, $user->home_ou, "RENEW_CIRC")) { return OpenILS::Perm->new("RENEW_CIRC"); @@ -740,92 +789,30 @@ sub renew { } if($circ->renewal_remaining <= 0) { - return OpenILS::EX->new("MAX_RENEWALS_REACHED")->ex; - } + return OpenILS::EX->new("MAX_RENEWALS_REACHED")->ex; } + + # XXX XXX See if the copy this circ points to is needed to fulfill a hold! # XXX check overdue..? - my $copy = _grab_copy_by_id($session, $circ->target_copy); my $checkin = $self->method_lookup("open-ils.circ.checkin.barcode"); my ($status) = $checkin->run($login_session, $copy->barcode, 1); return $status if ($status->{status} ne "0"); + warn "Renewal checkin completed for $iid\n"; my $permit_checkout = $self->method_lookup("open-ils.circ.permit_checkout"); ($status) = $permit_checkout->run($login_session, $copy->barcode, $circ->usr, "renew"); return $status if($status->{status} ne "0"); + warn "Renewal permit checkout completed for $iid\n"; my $checkout = $self->method_lookup("open-ils.circ.checkout.barcode"); ($status) = $checkout->run($login_session, $copy->barcode, $circ->usr, 1, $circ->renewal_remaining); + warn "Renewal checkout completed for $iid\n"; return $status; } -=head - - my $renew_objects = gather_renew_objects( $session, $circ ); - if(!ref($renew_objects)) { - if($renew_objects == NO_COPY) { - return { - status => NO_COPY, - text => "No copy available with id " . $circ->target_copy }; - } - } - - $stash = Template::Stash->new( - circ_objects => $renew_objects, - result => []); - - $stash->set("run_block", $permit_renew_script); - - # grab the number of copies checked out by the patron as - # well as the total fines - my $summary = _grab_patron_summary($session, $renew_objects->{patron}->id); - $summary->[0] ||= 0; - $summary->[1] ||= 0.0; - - $stash->set("patron_copies", $summary->[0] ); - $stash->set("patron_fines", $summary->[1] ); - - # run the permissibility script - run_script(); - - return $stash->get("result"); - -} - - - -sub gather_renew_objects { - my($session, $circ) = @_; - - _grab_patron_standings($session); - _grab_patron_profiles($session); - - # flesh me - my $copy = _grab_copy_by_id($session, $circ->target_copy); - if(!$copy) { return NO_COPY; } - - my $renew_objects = {}; - $renew_objects->{standings} = $patron_standings; - $renew_objects->{copy} = $copy; - $renew_objects->{circ} = $circ; - $renew_objects->{title} = _grab_title_by_copy($session, $copy->id); - my $patron = _grab_user($session, $circ->usr); - - $copy->status( $copy->status->name ); - $patron->standing($patron_standings->{$patron->standing()}); - $patron->profile( $patron_profiles->{$patron->profile}); - - $renew_objects->{patron} = $patron; - - return $renew_objects; -} - -=cut - - - 1; diff --git a/Open-ILS/src/perlmods/OpenILS/EX.pm b/Open-ILS/src/perlmods/OpenILS/EX.pm index eb5929942e..6db704d011 100644 --- a/Open-ILS/src/perlmods/OpenILS/EX.pm +++ b/Open-ILS/src/perlmods/OpenILS/EX.pm @@ -18,6 +18,7 @@ my %ex_types = ( PERMISSION_DENIED => 7, UNKNOWN_USER => 8, MAX_RENEWALS_REACHED => 9, + COPY_NEEDED_FOR_HOLD => 10, ); use overload ( '""' => sub { $_[0]->ex()->err_msg(); } ); diff --git a/Open-ILS/src/templates/strings/ex.ttk b/Open-ILS/src/templates/strings/ex.ttk index 1d9459c032..68b6fa8396 100644 --- a/Open-ILS/src/templates/strings/ex.ttk +++ b/Open-ILS/src/templates/strings/ex.ttk @@ -39,6 +39,9 @@ IF type == ex_types.MAX_RENEWALS_REACHED; ret("The maximun number of renewals has been reached"); END; + IF type == ex_types.COPY_NEEDED_FOR_HOLD; + ret("Copy is needed to fulfill a hold"); END; + ret("Unknown exception occured"); -%] diff --git a/Open-ILS/src/templates/strings/perm.ttk b/Open-ILS/src/templates/strings/perm.ttk index 05f4c5cbbc..fe9159dd09 100644 --- a/Open-ILS/src/templates/strings/perm.ttk +++ b/Open-ILS/src/templates/strings/perm.ttk @@ -19,6 +19,7 @@ perm_map.MR_HOLDS = "Metarecord/Title Group level holds"; perm_map.REQUEST_HOLDS = "Requesting a hold for another user"; perm_map.REQUEST_HOLDS_OVERRIDE = "Requesting a dissallowed hold for another user"; + perm_map.RENEW_HOLD_OVERRIDE = "Requesting renew for copy needed for hold"; ret(perm_map.$type); -- 2.43.2