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 if(ref($patron->card)) { $patron->card( $patron->card->id ); }
47 if(ref($patron->billing_address)) { $patron->billing_address( $patron->billing_address->id ); }
48 if(ref($patron->mailing_address)) { $patron->mailing_address( $patron->mailing_address->id ); }
50 # create/update the patron first so we can use his id
51 if($patron->isnew()) {
53 $new_patron = _add_patron($session, _clone_patron($patron), $user_obj);
55 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
56 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
57 $client->respond_complete($new_patron->ex);
61 } else { $new_patron = $patron; }
63 $new_patron = _add_update_addresses($session, $patron, $new_patron, $user_obj);
65 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
66 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
67 $client->respond_complete($new_patron->ex);
71 $new_patron = _add_update_cards($session, $patron, $new_patron, $user_obj);
73 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
74 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
75 $client->respond_complete($new_patron->ex);
79 $new_patron = _add_survey_responses($session, $patron, $new_patron, $user_obj);
80 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
81 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
82 $client->respond_complete($new_patron->ex);
86 $new_patron = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
87 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
88 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
89 $client->respond_complete($new_patron->ex);
94 # re-update the patron if anything has happened to him during this process
95 if($new_patron->ischanged()) {
96 $new_patron = _update_patron($session, $new_patron, $user_obj);
98 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
99 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
100 $client->respond_complete($new_patron->ex);
104 $apputils->commit_db_session($session);
106 warn "Patron Update/Create complete\n";
107 return flesh_user($new_patron->id());
113 __PACKAGE__->register_method(
114 method => "user_retrieve_fleshed_by_id",
115 api_name => "open-ils.actor.user.fleshed.retrieve",);
117 sub user_retrieve_fleshed_by_id {
118 my( $self, $client, $user_session, $user_id ) = @_;
119 my $user_obj = $apputils->check_user_session( $user_session );
121 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER")) {
122 return OpenILS::Perm->new("VIEW_USER");
125 return flesh_user($user_id);
136 $session = OpenSRF::AppSession->create("open-ils.storage");
140 # grab the user with the given id
141 my $ureq = $session->request(
142 "open-ils.storage.direct.actor.user.retrieve", $id);
143 my $user = $ureq->gather(1);
145 if(!$user) { return undef; }
148 my $cards_req = $session->request(
149 "open-ils.storage.direct.actor.card.search.usr.atomic",
151 $user->cards( $cards_req->gather(1) );
153 for my $c(@{$user->cards}) {
154 if($c->id == $user->card || $c->id eq $user->card ) {
155 warn "Setting my card to " . $c->id . "\n";
160 my $add_req = $session->request(
161 "open-ils.storage.direct.actor.user_address.search.usr.atomic",
163 $user->addresses( $add_req->gather(1) );
165 for my $c(@{$user->addresses}) {
166 if($c->id == $user->billing_address || $c->id eq $user->billing_address ) {
167 warn "Setting my address to " . $c->id . "\n";
168 $user->billing_address($c);
172 for my $c(@{$user->addresses}) {
173 if($c->id == $user->mailing_address || $c->id eq $user->mailing_address ) {
174 warn "Setting my address to " . $c->id . "\n";
175 $user->mailing_address($c);
179 my $stat_req = $session->request(
180 "open-ils.storage.direct.actor.stat_cat_entry_user_map.search.target_usr.atomic",
182 $user->stat_cat_entries($stat_req->gather(1));
184 if($kill) { $session->disconnect(); }
185 $user->clear_passwd();
193 # clone and clear stuff that would break the database
197 my $new_patron = Fieldmapper::actor::user->new();
199 my $fmap = $Fieldmapper::fieldmap;
200 no strict; # shallow clone, may be useful in the fieldmapper
202 (keys %{$fmap->{"Fieldmapper::actor::user"}->{'fields'}}) {
203 $new_patron->$field( $patron->$field() );
208 $new_patron->clear_billing_address();
209 $new_patron->clear_mailing_address();
210 $new_patron->clear_addresses();
211 $new_patron->clear_card();
212 $new_patron->clear_cards();
213 $new_patron->clear_id();
214 $new_patron->clear_isnew();
215 $new_patron->clear_changed();
216 $new_patron->clear_deleted();
217 $new_patron->clear_stat_cat_entries();
226 my $user_obj = shift;
229 if($apputils->check_user_perms(
230 $user_obj->id, $user_obj->home_ou, "CREATE_USER")) {
231 return OpenILS::Perm->new("CREATE_USER");
234 warn "Creating new patron\n";
237 my $req = $session->request(
238 "open-ils.storage.direct.actor.user.create",$patron);
239 my $id = $req->gather(1);
241 return OpenILS::EX->new("DUPLICATE_USER_USERNAME");
244 # retrieve the patron from the db to collect defaults
245 my $ureq = $session->request(
246 "open-ils.storage.direct.actor.user.retrieve",
249 warn "Created new patron with id $id\n";
251 return $ureq->gather(1);
256 my( $session, $patron, $user_obj) = @_;
259 if($apputils->check_user_perms(
260 $user_obj->id, $user_obj->home_ou, "UPDATE_USER")) {
261 return OpenILS::Perm->new("UPDATE_USER");
264 warn "updating patron " . Dumper($patron) . "\n";
266 my $req = $session->request(
267 "open-ils.storage.direct.actor.user.update",$patron );
268 my $status = $req->gather(1);
269 if(!defined($status)) {
270 throw OpenSRF::EX::ERROR
271 ("Unknown error updating patron");
277 sub _add_update_addresses {
280 my $new_patron = shift;
282 my $current_id; # id of the address before creation
284 for my $address (@{$patron->addresses()}) {
286 $address->usr($new_patron->id());
288 if(ref($address) and $address->isnew()) {
289 warn "Adding new address at street " . $address->street1() . "\n";
291 $current_id = $address->id();
292 $address = _add_address($session,$address);
294 if( $patron->billing_address() and
295 $patron->billing_address() == $current_id ) {
296 $new_patron->billing_address($address->id());
297 $new_patron->ischanged(1);
300 if( $patron->mailing_address() and
301 $patron->mailing_address() == $current_id ) {
302 $new_patron->mailing_address($address->id());
303 $new_patron->ischanged(1);
306 } elsif( ref($address) and $address->ischanged() ) {
307 warn "Updating address at street " . $address->street1();
308 $address->usr($new_patron->id());
309 _update_address($session,$address);
311 } elsif( ref($address) and $address->isdeleted() ) {
312 warn "Deleting address at street " . $address->street1();
314 if( $address->id() == $new_patron->mailing_address() ) {
315 $new_patron->clear_mailing_address();
316 _update_patron($session, $new_patron);
319 if( $address->id() == $new_patron->billing_address() ) {
320 $new_patron->clear_billing_address();
321 _update_patron($session, $new_patron);
324 _delete_address($session,$address);
332 # adds an address to the db and returns the address with new id
334 my($session, $address) = @_;
335 $address->clear_id();
337 # put the address into the database
338 my $req = $session->request(
339 "open-ils.storage.direct.actor.user_address.create",
343 my $id = $req->gather(1);
345 throw OpenSRF::EX::ERROR
346 ("Unable to create new user address");
349 warn "Created address with id $id\n";
351 # update all the necessary id's
357 sub _update_address {
358 my( $session, $address ) = @_;
359 my $req = $session->request(
360 "open-ils.storage.direct.actor.user_address.update",
362 my $status = $req->gather(1);
363 if(!defined($status)) {
364 throw OpenSRF::EX::ERROR
365 ("Unknown error updating address");
372 sub _add_update_cards {
376 my $new_patron = shift;
378 my $virtual_id; #id of the card before creation
379 for my $card (@{$patron->cards()}) {
381 $card->usr($new_patron->id());
383 if(ref($card) and $card->isnew()) {
385 $virtual_id = $card->id();
386 $card = _add_card($session,$card);
387 if(UNIVERSAL::isa($card,"OpenILS::EX")) {
391 #if(ref($patron->card)) { $patron->card($patron->card->id); }
392 if($patron->card() == $virtual_id) {
393 $new_patron->card($card->id());
394 $new_patron->ischanged(1);
397 } elsif( ref($card) and $card->ischanged() ) {
398 $card->usr($new_patron->id());
399 _update_card($session, $card);
406 # adds an card to the db and returns the card with new id
408 my( $session, $card ) = @_;
411 warn "Adding card with barcode " . $card->barcode() . "\n";
412 my $req = $session->request(
413 "open-ils.storage.direct.actor.card.create",
416 my $id = $req->gather(1);
418 return OpenILS::EX->new("DUPLICATE_INVALID_USER_BARCODE");
422 warn "Created patron card with id $id\n";
428 my( $session, $card ) = @_;
431 my $req = $session->request(
432 "open-ils.storage.direct.actor.card.update",
434 my $status = $req->gather(1);
435 if(!defined($status)) {
436 throw OpenSRF::EX::ERROR
437 ("Unknown error updating card");
445 sub _delete_address {
446 my( $session, $address ) = @_;
448 warn "Deleting address " . $address->street1() . "\n";
450 my $req = $session->request(
451 "open-ils.storage.direct.actor.user_address.delete",
453 my $status = $req->gather(1);
454 if(!defined($status)) {
455 throw OpenSRF::EX::ERROR
456 ("Unknown error updating address");
458 warn "Delete address status is $status\n";
463 sub _add_survey_responses {
464 my ($session, $patron, $new_patron) = @_;
466 warn "updating responses for user " . $new_patron->id . "\n";
468 my $responses = $patron->survey_responses;
472 for my $resp( @$responses ) {
473 $resp->usr($new_patron->id);
476 my $status = $apputils->simple_scalar_request(
478 "open-ils.circ.survey.submit.user_id",
487 sub _create_stat_maps {
489 my($session, $user_session, $patron, $new_patron) = @_;
491 my $maps = $patron->stat_cat_entries();
493 for my $map (@$maps) {
495 next unless($map->isnew() || $map->ischanged());
497 my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
499 $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.create";
502 $map->target_usr($new_patron->id);
504 warn "Updating stat entry with method $method and session $user_session and map $map\n";
506 my $req = $session->request($method, $map);
507 my $status = $req->gather(1);
512 throw OpenSRF::EX::ERROR
513 ("Error updating stat map with method $method");
522 __PACKAGE__->register_method(
523 method => "search_username",
524 api_name => "open-ils.actor.user.search.username",
527 sub search_username {
528 my($self, $client, $username) = @_;
529 my $users = OpenILS::Application::AppUtils->simple_scalar_request(
531 "open-ils.storage.direct.actor.user.search.usrname.atomic",
539 __PACKAGE__->register_method(
540 method => "user_retrieve_by_barcode",
541 api_name => "open-ils.actor.user.fleshed.retrieve_by_barcode",);
543 sub user_retrieve_by_barcode {
544 my($self, $client, $user_session, $barcode) = @_;
545 warn "Searching for user with barcode $barcode\n";
546 my $user_obj = $apputils->check_user_session( $user_session );
548 my $session = OpenSRF::AppSession->create("open-ils.storage");
550 # find the card with the given barcode
551 my $creq = $session->request(
552 "open-ils.storage.direct.actor.card.search.barcode.atomic",
554 my $card = $creq->gather(1);
556 if(!$card || !$card->[0]) {
557 $session->disconnect();
562 my $user = flesh_user($card->usr(), $session);
563 $session->disconnect();
570 __PACKAGE__->register_method(
571 method => "get_user_by_id",
572 api_name => "open-ils.actor.user.retrieve",);
575 my ($self, $client, $user_session, $id) = @_;
577 my $user_obj = $apputils->check_user_session( $user_session );
579 return $apputils->simple_scalar_request(
581 "open-ils.storage.direct.actor.user.retrieve",
587 __PACKAGE__->register_method(
588 method => "get_org_types",
589 api_name => "open-ils.actor.org_types.retrieve",);
593 my($self, $client) = @_;
595 return $org_types if $org_types;
597 $apputils->simple_scalar_request(
599 "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
604 __PACKAGE__->register_method(
605 method => "get_user_profiles",
606 api_name => "open-ils.actor.user.profiles.retrieve",
610 sub get_user_profiles {
611 return $user_profiles if $user_profiles;
613 return $user_profiles =
614 $apputils->simple_scalar_request(
616 "open-ils.storage.direct.actor.profile.retrieve.all.atomic");
621 __PACKAGE__->register_method(
622 method => "get_user_ident_types",
623 api_name => "open-ils.actor.user.ident_types.retrieve",
626 sub get_user_ident_types {
627 return $ident_types if $ident_types;
628 return $ident_types =
629 $apputils->simple_scalar_request(
631 "open-ils.storage.direct.config.identification_type.retrieve.all.atomic" );
637 __PACKAGE__->register_method(
638 method => "get_org_unit",
639 api_name => "open-ils.actor.org_unit.retrieve",
644 my( $self, $client, $user_session, $org_id ) = @_;
646 if(defined($user_session) && !defined($org_id)) {
648 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
649 if(!defined($org_id)) {
650 $org_id = $user_obj->home_ou;
655 my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request(
657 "open-ils.storage.direct.actor.org_unit.retrieve",
666 __PACKAGE__->register_method(
667 method => "get_org_tree",
668 api_name => "open-ils.actor.org_tree.retrieve",
670 note => "Returns the entire org tree structure",
674 my( $self, $client) = @_;
676 # see if it's in the cache
677 warn "Getting ORG Tree\n";
678 my $tree = $cache_client->get_cache('orgtree');
680 warn "Found orgtree in cache. returning...\n";
684 my $orglist = $apputils->simple_scalar_request(
686 "open-ils.storage.direct.actor.org_unit.retrieve.all.atomic" );
689 warn "found org list\n";
692 $tree = $self->build_org_tree($orglist);
693 $cache_client->put_cache('orgtree', $tree);
699 # turns an org list into an org tree
702 my( $self, $orglist) = @_;
704 return $orglist unless (
705 ref($orglist) and @$orglist > 1 );
708 $a->ou_type <=> $b->ou_type ||
709 $a->name cmp $b->name } @$orglist;
711 for my $org (@list) {
713 next unless ($org and defined($org->parent_ou));
714 my ($parent) = grep { $_->id == $org->parent_ou } @list;
717 $parent->children([]) unless defined($parent->children);
718 push( @{$parent->children}, $org );
726 __PACKAGE__->register_method(
727 method => "get_org_descendants",
728 api_name => "open-ils.actor.org_tree.descendants.retrieve"
731 # depth is optional. org_unit is the id
732 sub get_org_descendants {
733 my( $self, $client, $org_unit, $depth ) = @_;
734 my $orglist = $apputils->simple_scalar_request(
736 "open-ils.storage.actor.org_unit.descendants.atomic",
738 return $self->build_org_tree($orglist);
742 __PACKAGE__->register_method(
743 method => "get_org_ancestors",
744 api_name => "open-ils.actor.org_tree.ancestors.retrieve"
747 # depth is optional. org_unit is the id
748 sub get_org_ancestors {
749 my( $self, $client, $org_unit, $depth ) = @_;
750 my $orglist = $apputils->simple_scalar_request(
752 "open-ils.storage.actor.org_unit.ancestors.atomic",
754 return $self->build_org_tree($orglist);
758 __PACKAGE__->register_method(
759 method => "get_standings",
760 api_name => "open-ils.actor.standings.retrieve"
765 return $user_standings if $user_standings;
766 return $user_standings =
767 $apputils->simple_scalar_request(
769 "open-ils.storage.direct.config.standing.retrieve.all.atomic" );
774 __PACKAGE__->register_method(
775 method => "get_my_org_path",
776 api_name => "open-ils.actor.org_unit.full_path.retrieve"
779 sub get_my_org_path {
780 my( $self, $client, $user_session, $org_id ) = @_;
781 my $user_obj = $apputils->check_user_session($user_session);
782 if(!defined($org_id)) { $org_id = $user_obj->home_ou; }
784 return $apputils->simple_scalar_request(
786 "open-ils.storage.actor.org_unit.full_path.atomic",
791 __PACKAGE__->register_method(
792 method => "patron_adv_search",
793 api_name => "open-ils.actor.patron.search.advanced" );
795 sub patron_adv_search {
796 my( $self, $client, $staff_login, $search_hash ) = @_;
799 warn "patron adv with $staff_login and search " .
800 Dumper($search_hash) . "\n";
802 my $session = OpenSRF::AppSession->create("open-ils.storage");
803 my $req = $session->request(
804 "open-ils.storage.actor.user.crazy_search", $search_hash);
806 my $ans = $req->gather(1);
808 my %hash = map { ($_ =>1) } @$ans;
809 $ans = [ keys %hash ];
811 warn "Returning @$ans\n";
813 $session->disconnect();
820 sub _verify_password {
821 my($user_session, $password) = @_;
822 my $user_obj = $apputils->check_user_session($user_session);
824 #grab the user with password
825 $user_obj = $apputils->simple_scalar_request(
827 "open-ils.storage.direct.actor.user.retrieve",
830 if($user_obj->passwd eq $password) {
838 __PACKAGE__->register_method(
839 method => "update_password",
840 api_name => "open-ils.actor.user.password.update");
842 __PACKAGE__->register_method(
843 method => "update_password",
844 api_name => "open-ils.actor.user.username.update");
846 __PACKAGE__->register_method(
847 method => "update_password",
848 api_name => "open-ils.actor.user.email.update");
850 sub update_password {
851 my( $self, $client, $user_session, $new_value, $current_password ) = @_;
853 warn "Updating user with method " .$self->api_name . "\n";
854 my $user_obj = $apputils->check_user_session($user_session);
856 if($self->api_name =~ /password/) {
858 #make sure they know the current password
859 if(!_verify_password($user_session, md5_hex($current_password))) {
860 return OpenILS::EX->new("USER_WRONG_PASSWORD")->ex;
863 $user_obj->passwd($new_value);
865 elsif($self->api_name =~ /username/) {
866 $user_obj->usrname($new_value);
869 elsif($self->api_name =~ /email/) {
870 warn "Updating email to $new_value\n";
871 $user_obj->email($new_value);
874 my $session = $apputils->start_db_session();
875 $user_obj = _update_patron($session, $user_obj);
876 $apputils->commit_db_session($session);
878 if($user_obj) { return 1; }
883 __PACKAGE__->register_method(
884 method => "check_user_perms",
885 api_name => "open-ils.actor.user.perm.check",
886 notes => <<" NOTES");
887 Takes a login session, user id, an org id, and an array of perm type strings. For each
888 perm type, if the user does *not* have the given permission it is added
889 to a list which is returned from the method. If all permissions
890 are allowed, an empty list is returned
891 if the logged in user does not match 'user_id', then the logged in user must
892 have VIEW_PERMISSION priveleges.
895 sub check_user_perms {
896 my( $self, $client, $login_session, $user_id, $org_id, $perm_types ) = @_;
897 my $user_obj = $apputils->check_user_session($login_session);
899 if($user_obj->id ne $user_id) {
900 if($apputils->check_user_perms($user_obj->id, $org_id, "VIEW_PERMISSION")) {
901 return OpenILS::Perm->new("VIEW_PERMISSION");
906 for my $perm (@$perm_types) {
907 if($apputils->check_user_perms($user_id, $org_id, $perm)) {
908 push @not_allowed, $perm;
917 __PACKAGE__->register_method(
918 method => "user_fines_summary",
919 api_name => "open-ils.actor.user.fines.summary",
920 notes => <<" NOTES");
921 Returns a short summary of the users total open fines, excluding voided fines
922 Params are login_session, user_id
923 Returns a 'mus' object.
926 sub user_fines_summary {
927 my( $self, $client, $login_session, $user_id ) = @_;
929 my $user_obj = $apputils->check_user_session($login_session);
930 if($user_obj->id ne $user_id) {
931 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_FINES_SUMMARY")) {
932 return OpenILS::Perm->new("VIEW_USER_FINES_SUMMARY");
936 return $apputils->simple_scalar_request(
938 "open-ils.storage.direct.money.user_summary.search.usr",
946 __PACKAGE__->register_method(
947 method => "user_transactions",
948 api_name => "open-ils.actor.user.transactions",
949 notes => <<" NOTES");
950 Returns a list of open user transactions (mbts objects);
951 Params are login_session, user_id
952 Optional third parameter is the transactions type. defaults to all
955 __PACKAGE__->register_method(
956 method => "user_transactions",
957 api_name => "open-ils.actor.user.transactions.have_charge",
958 notes => <<" NOTES");
959 Returns a list of all open user transactions (mbts objects) that have an initial charge
960 Params are login_session, user_id
961 Optional third parameter is the transactions type. defaults to all
964 __PACKAGE__->register_method(
965 method => "user_transactions",
966 api_name => "open-ils.actor.user.transactions.have_balance",
967 notes => <<" NOTES");
968 Returns a list of all open user transactions (mbts objects) that have a balance
969 Params are login_session, user_id
970 Optional third parameter is the transactions type. defaults to all
973 __PACKAGE__->register_method(
974 method => "user_transactions",
975 api_name => "open-ils.actor.user.transactions.fleshed",
976 notes => <<" NOTES");
977 Returns an object/hash of transaction, circ, title where transaction = an open
978 user transactions (mbts objects), circ is the attached circluation, and title
979 is the title the circ points to
980 Params are login_session, user_id
981 Optional third parameter is the transactions type. defaults to all
984 __PACKAGE__->register_method(
985 method => "user_transactions",
986 api_name => "open-ils.actor.user.transactions.have_charge.fleshed",
987 notes => <<" NOTES");
988 Returns an object/hash of transaction, circ, title where transaction = an open
989 user transactions that has an initial charge (mbts objects), circ is the
990 attached circluation, and title is the title the circ points to
991 Params are login_session, user_id
992 Optional third parameter is the transactions type. defaults to all
995 __PACKAGE__->register_method(
996 method => "user_transactions",
997 api_name => "open-ils.actor.user.transactions.have_balance.fleshed",
998 notes => <<" NOTES");
999 Returns an object/hash of transaction, circ, title where transaction = an open
1000 user transaction that has a balance (mbts objects), circ is the attached
1001 circluation, and title is the title the circ points to
1002 Params are login_session, user_id
1003 Optional third parameter is the transaction type. defaults to all
1008 sub user_transactions {
1009 my( $self, $client, $login_session, $user_id, $type ) = @_;
1011 my $user_obj = $apputils->check_user_session($login_session);
1012 if($user_obj->id ne $user_id) {
1013 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_TRANSACTIONS")) {
1014 return OpenILS::Perm->new("VIEW_USER_TRANSACTIONS");
1018 my $api = $self->api_name();
1021 if(defined($type)) { @xact = (xact_type => $type);
1022 } else { @xact = (); }
1024 if($api =~ /have_charge/) {
1026 $trans = $apputils->simple_scalar_request(
1028 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1029 { usr => $user_id, total_owed => { ">" => 0 }, @xact });
1031 } elsif($api =~ /have_balance/) {
1033 $trans = $apputils->simple_scalar_request(
1035 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1036 { usr => $user_id, balance_owed => { ">" => 0 }, @xact });
1040 $trans = $apputils->simple_scalar_request(
1042 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1043 { usr => $user_id, @xact });
1046 if($api !~ /fleshed/) { return $trans; }
1051 for my $t (@$trans) {
1055 my $circ = $apputils->simple_scalar_request(
1057 "open-ils.storage.direct.action.circulation.retrieve",
1060 my $title = $apputils->simple_scalar_request(
1062 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
1063 $circ->target_copy );
1065 my $u = OpenILS::Utils::ModsParser->new();
1066 $u->start_mods_batch($title->marc());
1067 my $mods = $u->finish_mods_batch();
1069 push @resp, {transaction => $t, circ => $circ, record => $mods };
1079 __PACKAGE__->register_method(
1080 method => "retrieve_groups",
1081 api_name => "open-ils.actor.groups.retrieve",
1082 notes => <<" NOTES");
1083 Returns a list of user groups
1085 sub retrieve_groups {
1086 my( $self, $client ) = @_;
1087 return $apputils->simple_scalar_request(
1089 "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic");
1143 some old methods that may be good to keep around for now
1146 my( $session, $card ) = @_;
1148 warn "Deleting card with barcode " . $card->barcode() . "\n";
1149 my $req = $session->request(
1150 "open-ils.storage.direct.actor.card.delete",
1152 my $status = $req->gather(1);
1153 if(!defined($status)) {
1154 throw OpenSRF::EX::ERROR
1155 ("Unknown error updating card");
1161 # deletes the patron and any attached addresses and cards
1162 __PACKAGE__->register_method(
1163 method => "delete_patron",
1164 api_name => "open-ils.actor.patron.delete",
1169 my( $self, $client, $patron ) = @_;
1170 my $session = $apputils->start_db_session();
1175 $patron->clear_mailing_address();
1176 $patron->clear_billing_address();
1177 $patron->ischanged(1);
1179 _update_patron($session, $patron);
1180 _delete_address($session,$_) for (@{$patron->addresses()});
1181 _delete_card($session,$_) for (@{$patron->cards()});
1182 _delete_patron($session,$patron);
1183 $apputils->commit_db_session($session);
1185 } catch Error with {
1187 $err = "-*- Failure deleting user: $e";
1188 $apputils->rollback_db_session($session);
1192 if($err) { throw OpenSRF::EX::ERROR ($err); }
1193 warn "Patron Delete complete\n";
1197 sub _delete_patron {
1198 my( $session, $patron ) = @_;
1200 warn "Deleting patron " . $patron->usrname() . "\n";
1202 my $req = $session->request(
1203 "open-ils.storage.direct.actor.user.delete",
1205 my $status = $req->gather(1);
1206 if(!defined($status)) {
1207 throw OpenSRF::EX::ERROR
1208 ("Unknown error updating patron");