[open-ils-commits] r13555 - trunk/Open-ILS/src/perlmods/OpenILS/Application (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jul 9 10:31:46 EDT 2009
Author: erickson
Date: 2009-07-09 10:31:44 -0400 (Thu, 09 Jul 2009)
New Revision: 13555
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
added invalid patron address penalty creation/deletion. need to add penalty org_depth logic
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2009-07-09 14:28:36 UTC (rev 13554)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2009-07-09 14:31:44 UTC (rev 13555)
@@ -135,9 +135,6 @@
return 1;
}
-my $fetch_user_settings;
-my $fetch_ou_settings;
-
__PACKAGE__->register_method(
method => "user_settings",
api_name => "open-ils.actor.patron.settings.retrieve",
@@ -241,7 +238,6 @@
my $session = $apputils->start_db_session();
my $err = undef;
-
$logger->info("Creating new patron...") if $patron->isnew;
$logger->info("Updating Patron: " . $patron->id) unless $patron->isnew;
@@ -294,6 +290,9 @@
$apputils->commit_db_session($session);
+ $evt = apply_invalid_addr_penalty($patron);
+ return $evt if $evt;
+
my $tses = OpenSRF::AppSession->create('open-ils.trigger');
if($patron->isnew) {
$tses->request('open-ils.trigger.event.autocreate', 'au.create', $new_patron, $new_patron->home_ou);
@@ -304,7 +303,47 @@
return flesh_user($new_patron->id(), new_editor(requestor => $user_obj));
}
+sub apply_invalid_addr_penalty {
+ my $patron = shift;
+ my $e = new_editor(xact => 1);
+ # grab the invalid address penalty if set
+ my $penalties = OpenILS::Utils::Penalty->retrieve_usr_penalties($e, $patron->id, $patron->home_ou);
+
+ my ($addr_penalty) = grep
+ { $_->standing_penalty->name eq 'INVALID_PATRON_ADDRESS' } @$penalties;
+
+ # do we enforce invalid address penalty
+ my $enforce = $U->ou_ancestor_setting_value(
+ $patron->home_ou, 'circ.patron_invalid_address_apply_penalty') || 0;
+
+ my $addrs = $e->search_actor_user_address({usr => $patron->id, valid => 'f'}, {idlist => 1});
+ my $addr_count = scalar(@$addrs);
+
+ if($addr_count == 0 and $addr_penalty) {
+
+ # regardless of any settings, remove the penalty when the user has no invalid addresses
+ $e->delete_actor_user_standing_penalty($addr_penalty) or return $e->die_event;
+ $e->commit;
+
+ } elsif($enforce and $addr_count > 0 and !$addr_penalty) {
+
+ my $penalty = Fieldmapper::actor::user_standing_penalty->new;
+ $penalty->usr($patron->id);
+ $penalty->org_unit($patron->home_ou); # TODO: use depth
+ $penalty->standing_penalty(29); # INVALID_PATRON_ADDRESS (TODO: make me a constant, please)
+
+ $e->create_actor_user_standing_penalty($penalty) or return $e->die_event;
+ $e->commit;
+
+ } else {
+ $e->rollback;
+ }
+
+ return undef;
+}
+
+
sub flesh_user {
my $id = shift;
my $e = shift;
More information about the open-ils-commits
mailing list