1 package OpenILS::Application::Actor;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
6 use Digest::MD5 qw(md5_hex);
8 use OpenSRF::EX qw(:try);
11 use OpenILS::Application::AppUtils;
12 use OpenILS::Utils::Fieldmapper;
13 use OpenILS::Application::Search::Actor;
14 use OpenILS::Utils::ModsParser;
16 my $apputils = "OpenILS::Application::AppUtils";
17 sub _d { warn "Patron:\n" . Dumper(shift()); }
18 my $cache_client = OpenSRF::Utils::Cache->new("global", 0);
21 __PACKAGE__->register_method(
22 method => "update_patron",
23 api_name => "open-ils.actor.patron.update",);
26 my( $self, $client, $user_session, $patron ) = @_;
28 my $session = $apputils->start_db_session();
31 warn $user_session . " " . $patron . "\n";
35 OpenILS::Application::AppUtils->check_user_session(
36 $user_session ); #throws EX on error
38 # XXX does this user have permission to add/create users. Granularity?
40 # $new_patron is the patron in progress. $patron is the original patron
41 # passed in with the method. new_patron will change as the components
42 # of patron are added/updated.
46 # create/update the patron first so we can use his id
47 if($patron->isnew()) {
49 $new_patron = _add_patron($session, _clone_patron($patron), $user_obj);
51 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
52 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
53 $client->respond_complete($new_patron->ex);
57 } else { $new_patron = $patron; }
59 $new_patron = _add_update_addresses($session, $patron, $new_patron, $user_obj);
61 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
62 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
63 $client->respond_complete($new_patron->ex);
67 $new_patron = _add_update_cards($session, $patron, $new_patron, $user_obj);
69 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
70 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
71 $client->respond_complete($new_patron->ex);
75 $new_patron = _add_survey_responses($session, $patron, $new_patron, $user_obj);
76 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
77 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
78 $client->respond_complete($new_patron->ex);
82 $new_patron = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
83 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
84 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
85 $client->respond_complete($new_patron->ex);
90 # re-update the patron if anything has happened to him during this process
91 if($new_patron->ischanged()) {
92 $new_patron = _update_patron($session, $new_patron, $user_obj);
94 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
95 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
96 $client->respond_complete($new_patron->ex);
100 $apputils->commit_db_session($session);
102 warn "Patron Update/Create complete\n";
103 return flesh_user($new_patron->id());
109 __PACKAGE__->register_method(
110 method => "user_retrieve_fleshed_by_id",
111 api_name => "open-ils.actor.user.fleshed.retrieve",);
113 sub user_retrieve_fleshed_by_id {
114 my( $self, $client, $user_session, $user_id ) = @_;
115 my $user_obj = $apputils->check_user_session( $user_session );
116 return flesh_user($user_id);
127 $session = OpenSRF::AppSession->create("open-ils.storage");
131 # grab the user with the given id
132 my $ureq = $session->request(
133 "open-ils.storage.direct.actor.user.retrieve", $id);
134 my $user = $ureq->gather(1);
136 if(!$user) { return undef; }
139 my $cards_req = $session->request(
140 "open-ils.storage.direct.actor.card.search.usr.atomic",
142 $user->cards( $cards_req->gather(1) );
144 for my $c(@{$user->cards}) {
145 if($c->id == $user->card || $c->id eq $user->card ) {
146 warn "Setting my card to " . $c->id . "\n";
151 my $add_req = $session->request(
152 "open-ils.storage.direct.actor.user_address.search.usr.atomic",
154 $user->addresses( $add_req->gather(1) );
156 for my $c(@{$user->addresses}) {
157 if($c->id == $user->billing_address || $c->id eq $user->billing_address ) {
158 warn "Setting my address to " . $c->id . "\n";
159 $user->billing_address($c);
163 for my $c(@{$user->addresses}) {
164 if($c->id == $user->mailing_address || $c->id eq $user->mailing_address ) {
165 warn "Setting my address to " . $c->id . "\n";
166 $user->mailing_address($c);
170 my $stat_req = $session->request(
171 "open-ils.storage.direct.actor.stat_cat_entry_user_map.search.target_usr.atomic",
173 $user->stat_cat_entries($stat_req->gather(1));
175 if($kill) { $session->disconnect(); }
176 $user->clear_passwd();
184 # clone and clear stuff that would break the database
188 my $new_patron = Fieldmapper::actor::user->new();
190 my $fmap = $Fieldmapper::fieldmap;
191 no strict; # shallow clone, may be useful in the fieldmapper
193 (keys %{$fmap->{"Fieldmapper::actor::user"}->{'fields'}}) {
194 $new_patron->$field( $patron->$field() );
199 $new_patron->clear_billing_address();
200 $new_patron->clear_mailing_address();
201 $new_patron->clear_addresses();
202 $new_patron->clear_card();
203 $new_patron->clear_cards();
204 $new_patron->clear_id();
205 $new_patron->clear_isnew();
206 $new_patron->clear_changed();
207 $new_patron->clear_deleted();
208 $new_patron->clear_stat_cat_entries();
217 my $user_obj = shift;
220 if($apputils->check_user_perms(
221 $user_obj->id, $user_obj->home_ou, "CREATE_USER")) {
222 return OpenILS::Perm->new("CREATE_USER");
225 warn "Creating new patron\n";
228 my $req = $session->request(
229 "open-ils.storage.direct.actor.user.create",$patron);
230 my $id = $req->gather(1);
232 return OpenILS::EX->new("DUPLICATE_USER_USERNAME");
235 # retrieve the patron from the db to collect defaults
236 my $ureq = $session->request(
237 "open-ils.storage.direct.actor.user.retrieve",
240 warn "Created new patron with id $id\n";
242 return $ureq->gather(1);
247 my( $session, $patron, $user_obj) = @_;
250 if($apputils->check_user_perms(
251 $user_obj->id, $user_obj->home_ou, "UPDATE_USER")) {
252 return OpenILS::Perm->new("UPDATE_USER");
255 warn "updating patron " . Dumper($patron) . "\n";
257 my $req = $session->request(
258 "open-ils.storage.direct.actor.user.update",$patron );
259 my $status = $req->gather(1);
260 if(!defined($status)) {
261 throw OpenSRF::EX::ERROR
262 ("Unknown error updating patron");
268 sub _add_update_addresses {
271 my $new_patron = shift;
273 my $current_id; # id of the address before creation
275 for my $address (@{$patron->addresses()}) {
277 $address->usr($new_patron->id());
279 if(ref($address) and $address->isnew()) {
280 warn "Adding new address at street " . $address->street1() . "\n";
282 $current_id = $address->id();
283 $address = _add_address($session,$address);
285 if( $patron->billing_address() and
286 $patron->billing_address() == $current_id ) {
287 $new_patron->billing_address($address->id());
288 $new_patron->ischanged(1);
291 if( $patron->mailing_address() and
292 $patron->mailing_address() == $current_id ) {
293 $new_patron->mailing_address($address->id());
294 $new_patron->ischanged(1);
297 } elsif( ref($address) and $address->ischanged() ) {
298 warn "Updating address at street " . $address->street1();
299 $address->usr($new_patron->id());
300 _update_address($session,$address);
302 } elsif( ref($address) and $address->isdeleted() ) {
303 warn "Deleting address at street " . $address->street1();
305 if( $address->id() == $new_patron->mailing_address() ) {
306 $new_patron->clear_mailing_address();
307 _update_patron($session, $new_patron);
310 if( $address->id() == $new_patron->billing_address() ) {
311 $new_patron->clear_billing_address();
312 _update_patron($session, $new_patron);
315 _delete_address($session,$address);
323 # adds an address to the db and returns the address with new id
325 my($session, $address) = @_;
326 $address->clear_id();
328 # put the address into the database
329 my $req = $session->request(
330 "open-ils.storage.direct.actor.user_address.create",
334 my $id = $req->gather(1);
336 throw OpenSRF::EX::ERROR
337 ("Unable to create new user address");
340 warn "Created address with id $id\n";
342 # update all the necessary id's
348 sub _update_address {
349 my( $session, $address ) = @_;
350 my $req = $session->request(
351 "open-ils.storage.direct.actor.user_address.update",
353 my $status = $req->gather(1);
354 if(!defined($status)) {
355 throw OpenSRF::EX::ERROR
356 ("Unknown error updating address");
363 sub _add_update_cards {
367 my $new_patron = shift;
369 my $virtual_id; #id of the card before creation
370 for my $card (@{$patron->cards()}) {
372 $card->usr($new_patron->id());
374 if(ref($card) and $card->isnew()) {
376 $virtual_id = $card->id();
377 $card = _add_card($session,$card);
378 if(UNIVERSAL::isa($card,"OpenILS::EX")) {
382 if($patron->card() == $virtual_id) {
383 $new_patron->card($card->id());
384 $new_patron->ischanged(1);
387 } elsif( ref($card) and $card->ischanged() ) {
388 $card->usr($new_patron->id());
389 _update_card($session, $card);
396 # adds an card to the db and returns the card with new id
398 my( $session, $card ) = @_;
401 warn "Adding card with barcode " . $card->barcode() . "\n";
402 my $req = $session->request(
403 "open-ils.storage.direct.actor.card.create",
406 my $id = $req->gather(1);
408 return OpenILS::EX->new("DUPLICATE_INVALID_USER_BARCODE");
412 warn "Created patron card with id $id\n";
418 my( $session, $card ) = @_;
421 my $req = $session->request(
422 "open-ils.storage.direct.actor.card.update",
424 my $status = $req->gather(1);
425 if(!defined($status)) {
426 throw OpenSRF::EX::ERROR
427 ("Unknown error updating card");
435 sub _delete_address {
436 my( $session, $address ) = @_;
438 warn "Deleting address " . $address->street1() . "\n";
440 my $req = $session->request(
441 "open-ils.storage.direct.actor.user_address.delete",
443 my $status = $req->gather(1);
444 if(!defined($status)) {
445 throw OpenSRF::EX::ERROR
446 ("Unknown error updating address");
448 warn "Delete address status is $status\n";
453 sub _add_survey_responses {
454 my ($session, $patron, $new_patron) = @_;
456 warn "updating responses for user " . $new_patron->id . "\n";
458 my $responses = $patron->survey_responses;
459 for my $resp( @$responses ) {
460 $resp->usr($new_patron->id);
463 my $status = $apputils->simple_scalar_request(
465 "open-ils.circ.survey.submit.user_id",
472 sub _create_stat_maps {
474 my($session, $user_session, $patron, $new_patron) = @_;
476 my $maps = $patron->stat_cat_entries();
478 for my $map (@$maps) {
480 next unless($map->isnew() || $map->ischanged());
482 my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
484 $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.create";
487 $map->target_usr($new_patron->id);
489 warn "Updating stat entry with method $method and session $user_session and map $map\n";
491 my $req = $session->request($method, $map);
492 my $status = $req->gather(1);
497 throw OpenSRF::EX::ERROR
498 ("Error updating stat map with method $method");
507 __PACKAGE__->register_method(
508 method => "search_username",
509 api_name => "open-ils.actor.user.search.username",
512 sub search_username {
513 my($self, $client, $username) = @_;
514 my $users = OpenILS::Application::AppUtils->simple_scalar_request(
516 "open-ils.storage.direct.actor.user.search.usrname.atomic",
524 __PACKAGE__->register_method(
525 method => "user_retrieve_by_barcode",
526 api_name => "open-ils.actor.user.fleshed.retrieve_by_barcode",);
528 sub user_retrieve_by_barcode {
529 my($self, $client, $user_session, $barcode) = @_;
530 warn "Searching for user with barcode $barcode\n";
531 my $user_obj = $apputils->check_user_session( $user_session );
533 my $session = OpenSRF::AppSession->create("open-ils.storage");
535 # find the card with the given barcode
536 my $creq = $session->request(
537 "open-ils.storage.direct.actor.card.search.barcode.atomic",
539 my $card = $creq->gather(1);
541 if(!$card || !$card->[0]) {
542 $session->disconnect();
547 my $user = flesh_user($card->usr(), $session);
548 $session->disconnect();
555 __PACKAGE__->register_method(
556 method => "get_user_by_id",
557 api_name => "open-ils.actor.user.retrieve",);
560 my ($self, $client, $user_session, $id) = @_;
562 my $user_obj = $apputils->check_user_session( $user_session );
564 return $apputils->simple_scalar_request(
566 "open-ils.storage.direct.actor.user.retrieve",
572 __PACKAGE__->register_method(
573 method => "get_org_types",
574 api_name => "open-ils.actor.org_types.retrieve",);
578 my($self, $client) = @_;
580 return $org_types if $org_types;
582 $apputils->simple_scalar_request(
584 "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
589 __PACKAGE__->register_method(
590 method => "get_user_profiles",
591 api_name => "open-ils.actor.user.profiles.retrieve",
595 sub get_user_profiles {
596 return $user_profiles if $user_profiles;
598 return $user_profiles =
599 $apputils->simple_scalar_request(
601 "open-ils.storage.direct.actor.profile.retrieve.all.atomic");
606 __PACKAGE__->register_method(
607 method => "get_user_ident_types",
608 api_name => "open-ils.actor.user.ident_types.retrieve",
611 sub get_user_ident_types {
612 return $ident_types if $ident_types;
613 return $ident_types =
614 $apputils->simple_scalar_request(
616 "open-ils.storage.direct.config.identification_type.retrieve.all.atomic" );
622 __PACKAGE__->register_method(
623 method => "get_org_unit",
624 api_name => "open-ils.actor.org_unit.retrieve",
629 my( $self, $client, $user_session, $org_id ) = @_;
631 if(defined($user_session) && !defined($org_id)) {
633 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
634 if(!defined($org_id)) {
635 $org_id = $user_obj->home_ou;
640 my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request(
642 "open-ils.storage.direct.actor.org_unit.retrieve",
651 __PACKAGE__->register_method(
652 method => "get_org_tree",
653 api_name => "open-ils.actor.org_tree.retrieve",
655 note => "Returns the entire org tree structure",
659 my( $self, $client) = @_;
661 # see if it's in the cache
662 warn "Getting ORG Tree\n";
663 my $tree = $cache_client->get_cache('orgtree');
665 warn "Found orgtree in cache. returning...\n";
669 my $orglist = $apputils->simple_scalar_request(
671 "open-ils.storage.direct.actor.org_unit.retrieve.all.atomic" );
674 warn "found org list\n";
677 $tree = $self->build_org_tree($orglist);
678 $cache_client->put_cache('orgtree', $tree);
684 # turns an org list into an org tree
687 my( $self, $orglist) = @_;
689 return $orglist unless (
690 ref($orglist) and @$orglist > 1 );
693 $a->ou_type <=> $b->ou_type ||
694 $a->name cmp $b->name } @$orglist;
696 for my $org (@list) {
698 next unless ($org and defined($org->parent_ou));
699 my ($parent) = grep { $_->id == $org->parent_ou } @list;
702 $parent->children([]) unless defined($parent->children);
703 push( @{$parent->children}, $org );
711 __PACKAGE__->register_method(
712 method => "get_org_descendants",
713 api_name => "open-ils.actor.org_tree.descendants.retrieve"
716 # depth is optional. org_unit is the id
717 sub get_org_descendants {
718 my( $self, $client, $org_unit, $depth ) = @_;
719 my $orglist = $apputils->simple_scalar_request(
721 "open-ils.storage.actor.org_unit.descendants.atomic",
723 return $self->build_org_tree($orglist);
727 __PACKAGE__->register_method(
728 method => "get_org_ancestors",
729 api_name => "open-ils.actor.org_tree.ancestors.retrieve"
732 # depth is optional. org_unit is the id
733 sub get_org_ancestors {
734 my( $self, $client, $org_unit, $depth ) = @_;
735 my $orglist = $apputils->simple_scalar_request(
737 "open-ils.storage.actor.org_unit.ancestors.atomic",
739 return $self->build_org_tree($orglist);
743 __PACKAGE__->register_method(
744 method => "get_standings",
745 api_name => "open-ils.actor.standings.retrieve"
750 return $user_standings if $user_standings;
751 return $user_standings =
752 $apputils->simple_scalar_request(
754 "open-ils.storage.direct.config.standing.retrieve.all.atomic" );
759 __PACKAGE__->register_method(
760 method => "get_my_org_path",
761 api_name => "open-ils.actor.org_unit.full_path.retrieve"
764 sub get_my_org_path {
765 my( $self, $client, $user_session, $org_id ) = @_;
766 my $user_obj = $apputils->check_user_session($user_session);
767 if(!defined($org_id)) { $org_id = $user_obj->home_ou; }
769 return $apputils->simple_scalar_request(
771 "open-ils.storage.actor.org_unit.full_path.atomic",
776 __PACKAGE__->register_method(
777 method => "patron_adv_search",
778 api_name => "open-ils.actor.patron.search.advanced" );
780 sub patron_adv_search {
781 my( $self, $client, $staff_login, $search_hash ) = @_;
784 warn "patron adv with $staff_login and search " .
785 Dumper($search_hash) . "\n";
787 my $session = OpenSRF::AppSession->create("open-ils.storage");
788 my $req = $session->request(
789 "open-ils.storage.actor.user.crazy_search", $search_hash);
791 my $ans = $req->gather(1);
793 my %hash = map { ($_ =>1) } @$ans;
794 $ans = [ keys %hash ];
796 warn "Returning @$ans\n";
798 $session->disconnect();
805 sub _verify_password {
806 my($user_session, $password) = @_;
807 my $user_obj = $apputils->check_user_session($user_session);
809 #grab the user with password
810 $user_obj = $apputils->simple_scalar_request(
812 "open-ils.storage.direct.actor.user.retrieve",
815 if($user_obj->passwd eq $password) {
823 __PACKAGE__->register_method(
824 method => "update_password",
825 api_name => "open-ils.actor.user.password.update");
827 __PACKAGE__->register_method(
828 method => "update_password",
829 api_name => "open-ils.actor.user.username.update");
831 __PACKAGE__->register_method(
832 method => "update_password",
833 api_name => "open-ils.actor.user.email.update");
835 sub update_password {
836 my( $self, $client, $user_session, $new_value, $current_password ) = @_;
838 warn "Updating user with method " .$self->api_name . "\n";
839 my $user_obj = $apputils->check_user_session($user_session);
841 if($self->api_name =~ /password/) {
843 #make sure they know the current password
844 if(!_verify_password($user_session, md5_hex($current_password))) {
845 return OpenILS::EX->new("USER_WRONG_PASSWORD")->ex;
848 $user_obj->passwd($new_value);
850 elsif($self->api_name =~ /username/) {
851 $user_obj->usrname($new_value);
854 elsif($self->api_name =~ /email/) {
855 warn "Updating email to $new_value\n";
856 $user_obj->email($new_value);
859 my $session = $apputils->start_db_session();
860 $user_obj = _update_patron($session, $user_obj);
861 $apputils->commit_db_session($session);
863 if($user_obj) { return 1; }
868 __PACKAGE__->register_method(
869 method => "check_user_perms",
870 api_name => "open-ils.actor.user.perm.check",
871 notes => <<" NOTES");
872 Takes a login session, user id, an org id, and an array of perm type strings. For each
873 perm type, if the user does *not* have the given permission it is added
874 to a list which is returned from the method. If all permissions
875 are allowed, an empty list is returned
876 if the logged in user does not match 'user_id', then the logged in user must
877 have VIEW_PERMISSION priveleges.
880 sub check_user_perms {
881 my( $self, $client, $login_session, $user_id, $org_id, $perm_types ) = @_;
882 my $user_obj = $apputils->check_user_session($login_session);
884 if($user_obj->id ne $user_id) {
885 if($apputils->check_user_perms($user_obj->id, $org_id, "VIEW_PERMISSION")) {
886 return OpenILS::Perm->new("VIEW_PERMISSION");
891 for my $perm (@$perm_types) {
892 if($apputils->check_user_perms($user_id, $org_id, $perm)) {
893 push @not_allowed, $perm;
902 __PACKAGE__->register_method(
903 method => "user_fines_summary",
904 api_name => "open-ils.actor.user.fines.summary",
905 notes => <<" NOTES");
906 Returns a short summary of the users total open fines, excluding voided fines
907 Params are login_session, user_id
908 Returns a 'mus' object.
911 sub user_fines_summary {
912 my( $self, $client, $login_session, $user_id ) = @_;
914 my $user_obj = $apputils->check_user_session($login_session);
915 if($user_obj->id ne $user_id) {
916 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_FINES_SUMMARY")) {
917 return OpenILS::Perm->new("VIEW_USER_FINES_SUMMARY");
921 return $apputils->simple_scalar_request(
923 "open-ils.storage.direct.money.user_summary.search.usr",
931 __PACKAGE__->register_method(
932 method => "user_transactions",
933 api_name => "open-ils.actor.user.transactions",
934 notes => <<" NOTES");
935 Returns a list of open user transactions (mbts objects);
936 Params are login_session, user_id
937 Optional third parameter is the transactions type. defaults to all
940 __PACKAGE__->register_method(
941 method => "user_transactions",
942 api_name => "open-ils.actor.user.transactions.have_charge",
943 notes => <<" NOTES");
944 Returns a list of all open user transactions (mbts objects) that have an initial charge
945 Params are login_session, user_id
946 Optional third parameter is the transactions type. defaults to all
949 __PACKAGE__->register_method(
950 method => "user_transactions",
951 api_name => "open-ils.actor.user.transactions.have_balance",
952 notes => <<" NOTES");
953 Returns a list of all open user transactions (mbts objects) that have a balance
954 Params are login_session, user_id
955 Optional third parameter is the transactions type. defaults to all
958 __PACKAGE__->register_method(
959 method => "user_transactions",
960 api_name => "open-ils.actor.user.transactions.fleshed",
961 notes => <<" NOTES");
962 Returns an object/hash of transaction, circ, title where transaction = an open
963 user transactions (mbts objects), circ is the attached circluation, and title
964 is the title the circ points to
965 Params are login_session, user_id
966 Optional third parameter is the transactions type. defaults to all
969 __PACKAGE__->register_method(
970 method => "user_transactions",
971 api_name => "open-ils.actor.user.transactions.have_charge.fleshed",
972 notes => <<" NOTES");
973 Returns an object/hash of transaction, circ, title where transaction = an open
974 user transactions that has an initial charge (mbts objects), circ is the
975 attached circluation, and title is the title the circ points to
976 Params are login_session, user_id
977 Optional third parameter is the transactions type. defaults to all
980 __PACKAGE__->register_method(
981 method => "user_transactions",
982 api_name => "open-ils.actor.user.transactions.have_balance.fleshed",
983 notes => <<" NOTES");
984 Returns an object/hash of transaction, circ, title where transaction = an open
985 user transaction that has a balance (mbts objects), circ is the attached
986 circluation, and title is the title the circ points to
987 Params are login_session, user_id
988 Optional third parameter is the transaction type. defaults to all
993 sub user_transactions {
994 my( $self, $client, $login_session, $user_id, $type ) = @_;
996 my $user_obj = $apputils->check_user_session($login_session);
997 if($user_obj->id ne $user_id) {
998 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_TRANSACTIONS")) {
999 return OpenILS::Perm->new("VIEW_USER_TRANSACTIONS");
1003 my $api = $self->api_name();
1006 if(defined($type)) { @xact = (xact_type => $type);
1007 } else { @xact = (); }
1009 if($api =~ /have_charge/) {
1011 $trans = $apputils->simple_scalar_request(
1013 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1014 { usr => $user_id, total_owed => { ">" => 0 }, @xact });
1016 } elsif($api =~ /have_balance/) {
1018 $trans = $apputils->simple_scalar_request(
1020 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1021 { usr => $user_id, balance_owed => { ">" => 0 }, @xact });
1025 $trans = $apputils->simple_scalar_request(
1027 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1028 { usr => $user_id, @xact });
1031 if($api !~ /fleshed/) { return $trans; }
1036 for my $t (@$trans) {
1040 my $circ = $apputils->simple_scalar_request(
1042 "open-ils.storage.direct.action.circulation.retrieve",
1045 my $title = $apputils->simple_scalar_request(
1047 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
1048 $circ->target_copy );
1050 my $u = OpenILS::Utils::ModsParser->new();
1051 $u->start_mods_batch($title->marc());
1052 my $mods = $u->finish_mods_batch();
1054 push @resp, {transaction => $t, circ => $circ, record => $mods };
1064 __PACKAGE__->register_method(
1065 method => "retrieve_groups",
1066 api_name => "open-ils.actor.groups.retrieve",
1067 notes => <<" NOTES");
1068 Returns a list of user groups
1070 sub retrieve_groups {
1071 my( $self, $client ) = @_;
1072 return $apputils->simple_scalar_request(
1074 "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic");
1128 some old methods that may be good to keep around for now
1131 my( $session, $card ) = @_;
1133 warn "Deleting card with barcode " . $card->barcode() . "\n";
1134 my $req = $session->request(
1135 "open-ils.storage.direct.actor.card.delete",
1137 my $status = $req->gather(1);
1138 if(!defined($status)) {
1139 throw OpenSRF::EX::ERROR
1140 ("Unknown error updating card");
1146 # deletes the patron and any attached addresses and cards
1147 __PACKAGE__->register_method(
1148 method => "delete_patron",
1149 api_name => "open-ils.actor.patron.delete",
1154 my( $self, $client, $patron ) = @_;
1155 my $session = $apputils->start_db_session();
1160 $patron->clear_mailing_address();
1161 $patron->clear_billing_address();
1162 $patron->ischanged(1);
1164 _update_patron($session, $patron);
1165 _delete_address($session,$_) for (@{$patron->addresses()});
1166 _delete_card($session,$_) for (@{$patron->cards()});
1167 _delete_patron($session,$patron);
1168 $apputils->commit_db_session($session);
1170 } catch Error with {
1172 $err = "-*- Failure deleting user: $e";
1173 $apputils->rollback_db_session($session);
1177 if($err) { throw OpenSRF::EX::ERROR ($err); }
1178 warn "Patron Delete complete\n";
1182 sub _delete_patron {
1183 my( $session, $patron ) = @_;
1185 warn "Deleting patron " . $patron->usrname() . "\n";
1187 my $req = $session->request(
1188 "open-ils.storage.direct.actor.user.delete",
1190 my $status = $req->gather(1);
1191 if(!defined($status)) {
1192 throw OpenSRF::EX::ERROR
1193 ("Unknown error updating patron");