From bd98f2adea3937bd848cf0386e8220095e3d8118 Mon Sep 17 00:00:00 2001
From: Bill Erickson <berick@esilibrary.com>
Date: Thu, 21 Jun 2012 14:37:11 -0400
Subject: [PATCH] Avoid CAPTURE-blocked holds in pull list (IDL view)

Update the new IDL holds pull list view to avoid returning holds for
users that have CAPTURE penalties.

Note that items are blocked from the pull list only if the hold pickup
lib is within the CAPTURE penalty org unit range.  This means that users
could be blocked at one branch, but use a pickup lib at another to avoid
the block.  To prevent this type of abuse, set the org_depth to 0 on any
penalties that apply the CAPTURE block.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
---
 Open-ILS/examples/fm_IDL.xml | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index a3cda7c0b7..dba33cf175 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -5048,6 +5048,18 @@ SELECT  usr,
 		JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id)
 		JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id)
 		JOIN actor.usr au ON (au.id = ahr.usr)
+		LEFT JOIN actor.usr_standing_penalty ausp 
+			ON (ahr.usr = ausp.usr AND (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
+		LEFT JOIN config.standing_penalty csp
+			ON (
+				csp.id = ausp.standing_penalty AND 
+				csp.block_list LIKE '%CAPTURE%' AND (
+					(csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
+					(csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
+						SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
+					)
+				)
+			)
 		LEFT JOIN serial.issuance siss
 			ON (ahr.hold_type = 'I' AND siss.id = ahr.target)
 		LEFT JOIN asset.copy_location_order acplo
@@ -5056,6 +5068,7 @@ SELECT  usr,
 		WHERE
 			ahr.capture_time IS NULL AND
 			ahr.cancel_time IS NULL AND
+			csp.id IS NULL AND
 			(ahr.expire_time is NULL OR ahr.expire_time > NOW())
 		]]></oils_persist:source_definition>
 		<fields oils_persist:primary="id">
-- 
2.11.0