1. OK to have duplicate usr_standing_penalty's. 2. find the best context org using...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Jul 2009 20:22:17 +0000 (20:22 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Jul 2009 20:22:17 +0000 (20:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13616 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm

index 68503d1..7d1c5b1 100644 (file)
@@ -2679,23 +2679,24 @@ __PACKAGE__->register_method(
 
 sub apply_penalty {
        my($self, $conn, $auth, $penalty) = @_;
+
        my $e = new_editor(authtoken=>$auth, xact => 1);
        return $e->die_event unless $e->checkauth;
+
     my $user = $e->retrieve_actor_user($penalty->usr) or return $e->die_event;
     return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou);
 
-    # is it already applied?
-    return 1 if $e->search_actor_user_standing_penalty(
-        {   usr => $penalty->usr, 
-            '-or' => [
-                {stop_date => undef},
-                {stop_date => {'>' => 'now'}}
-            ],
-            standing_penalty => $penalty->standing_penalty,
-            org_unit => $penalty->org_unit
-        })->[0];
+    my $ptype = $e->retrieve_config_standing_penalty($penalty->standing_penalty) or return $e->die_event;
+    
+    my $ctx_org = 
+        (defined $ptype->org_depth) ?
+        $U->org_unit_ancestor_at_depth($penalty->org_unit, $ptype->org_depth) :
+        $penalty->org_unit;
 
+    $penalty->org_unit($ctx_org);
+    $penalty->staff($e->requestor->id);
     $e->create_actor_user_standing_penalty($penalty) or return $e->die_event;
+
     $e->commit;
     return $penalty->id;
 }