From a7208402108396ce12059086ea065decb8fbf3a1 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 28 May 2010 14:19:21 +0000 Subject: [PATCH] API calls to expose the circ/hold history stored procedures moved circ chain summary creator code to apputils for sharing git-svn-id: svn://svn.open-ils.org/ILS/trunk@16529 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 84 ++++++++++++++++++++++ .../src/perlmods/OpenILS/Application/AppUtils.pm | 9 +++ Open-ILS/src/perlmods/OpenILS/Application/Circ.pm | 6 +- 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index b81d5ac922..3d21d503a3 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -3981,5 +3981,89 @@ sub event_def_opt_in_settings { } +__PACKAGE__->register_method( + method => "user_visible_circs", + api_name => "open-ils.actor.history.circ.visible", + stream => 1, + signature => { + desc => 'Returns the set of opt-in visible circulations accompanied by circulation chain summaries', + params => [ + { desc => 'Authentication token', type => 'string'}, + { desc => 'User ID. If no user id is present, the authenticated user is assumed', type => 'number' }, + { desc => 'Options hash. Supported fields are "limit" and "offset"', type => 'object' }, + ], + return => { + desc => q/An object with 2 fields: circulation and summary. + circulation is the "circ" object. summary is the related "accs" object/, + type => 'object', + } + } +); + +__PACKAGE__->register_method( + method => "user_visible_circs", + api_name => "open-ils.actor.history.hold.visible", + stream => 1, + signature => { + desc => 'Returns the set of opt-in visible holds', + params => [ + { desc => 'Authentication token', type => 'string'}, + { desc => 'User ID. If no user id is present, the authenticated user is assumed', type => 'number' }, + { desc => 'Options hash. Supported fields are "limit" and "offset"', type => 'object' }, + ], + return => { + desc => q/An object with 1 field: "hold"/, + type => 'object', + } + } +); + + +sub user_visible_circs { + my($self, $conn, $auth, $user_id, $options) = @_; + + my $is_hold = ($self->api_name =~ /hold/); + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + $user_id ||= $e->requestor->id; + $options ||= {}; + $options->{limit} ||= 50; + $options->{offset} ||= 0; + + if($user_id != $e->requestor->id) { + my $perm = ($is_hold) ? 'VIEW_HOLD' : 'VIEW_CIRCULATIONS'; + my $user = $e->retrieve_actor_user($user_id) or return $e->event; + return $e->event unless $e->allowed($perm, $user->home_ou); + } + + my $db_func = ($is_hold) ? 'action.usr_visible_holds' : 'action.usr_visible_circs'; + + my $data = $e->json_query({ + from => [$db_func, $user_id], + limit => $$options{limit}, + offset => $$options{offset} + + # TODO: I only want IDs. code below didn't get me there + # {"select":{"au":[{"column":"id", "result_field":"id", + # "transform":"action.usr_visible_circs"}]}, "where":{"id":10}, "from":"au"} + }); + + foreach (@$data) { + my $id = $_->{id}; + if($is_hold) { + $conn->respond({hold => $e->retrieve_action_hold_request($id)}); + } else { + $conn->respond({ + circ => $e->retrieve_action_circulation($id), + summary => $U->create_circ_chain_summary($e, $id) + }); + } + } + + return undef; +} + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 97f04b2e27..d9165f8f3b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1676,5 +1676,14 @@ sub create_uuid_string { return create_UUID_as_string(); } +sub create_circ_chain_summary { + my($class, $e, $circ_id) = @_; + my $sum = $e->json_query({from => ['action.summarize_circ_chain', $circ_id]})->[0]; + return undef unless $sum; + my $obj = Fieldmapper::action::circ_chain_summary->new; + $obj->$_($sum->{$_}) for keys %$sum; + return $obj; +} + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index bd259818e0..16bd62ef13 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -1476,11 +1476,7 @@ sub retrieve_circ_chain { return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); if($self->api_name =~ /summary/) { - my $sum = $e->json_query({from => ['action.summarize_circ_chain', $circ_id]})->[0]; - return undef unless $sum; - my $obj = Fieldmapper::action::circ_chain_summary->new; - $obj->$_($sum->{$_}) for keys %$sum; - return $obj; + return $U->create_circ_chain_summary($e, $circ_id); } else { -- 2.11.0