From 6a3ce62863bb5a4e7ff68a2eda40ef7ef33ab4f0 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 20 Nov 2008 22:10:07 +0000 Subject: [PATCH] beginning the org_unit-ification of penalties git-svn-id: svn://svn.open-ils.org/ILS/trunk@11292 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 4 ++ Open-ILS/src/sql/Pg/005.schema.actors.sql | 62 +++++++++++++------------- Open-ILS/src/sql/Pg/006.schema.permissions.sql | 3 +- Open-ILS/src/sql/Pg/100.circ_matrix.sql | 12 ++--- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 10 ++--- 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 08c29812ef..0ca7d717e6 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1725,10 +1725,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + @@ -1761,9 +1763,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql index 5a105c90f7..ceef438a0d 100644 --- a/Open-ILS/src/sql/Pg/005.schema.actors.sql +++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql @@ -144,36 +144,6 @@ CREATE TABLE actor.usr_note ( ); CREATE INDEX actor_usr_note_usr_idx ON actor.usr_note (usr); -CREATE TABLE actor.usr_standing_penalty ( - id SERIAL PRIMARY KEY, - usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - standing_penalty INT NOT NULL REFERENCES config.standing_penalty (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - staff INT REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, - set_date TIMESTAMP WITH TIME ZONE DEFAULT NOW() -); -COMMENT ON TABLE actor.usr_standing_penalty IS $$ -/* - * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service - * Mike Rylander - * - * User standing penalties - * - * **** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ -$$; - -CREATE INDEX actor_usr_standing_penalty_usr_idx ON actor.usr_standing_penalty (usr); - CREATE TABLE actor.usr_setting ( id BIGSERIAL PRIMARY KEY, usr INT NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, @@ -517,4 +487,36 @@ CREATE OR REPLACE FUNCTION public.first5 ( TEXT ) RETURNS TEXT AS $$ SELECT SUBSTRING( $1, 1, 5); $$ LANGUAGE SQL; +CREATE TABLE actor.usr_standing_penalty ( + id SERIAL PRIMARY KEY, + org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + usr INT NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + standing_penalty INT NOT NULL REFERENCES config.standing_penalty (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + staff INT REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, + set_date TIMESTAMP WITH TIME ZONE DEFAULT NOW() +); +COMMENT ON TABLE actor.usr_standing_penalty IS $$ +/* + * Copyright (C) 2005-2008 Equinox Software, Inc. / Georgia Public Library Service + * Mike Rylander + * + * User standing penalties + * + * **** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +$$; + +CREATE INDEX actor_usr_standing_penalty_usr_idx ON actor.usr_standing_penalty (usr); + + COMMIT; diff --git a/Open-ILS/src/sql/Pg/006.schema.permissions.sql b/Open-ILS/src/sql/Pg/006.schema.permissions.sql index 99f8cbc185..e3a85ba05d 100644 --- a/Open-ILS/src/sql/Pg/006.schema.permissions.sql +++ b/Open-ILS/src/sql/Pg/006.schema.permissions.sql @@ -40,8 +40,9 @@ CREATE TABLE permission.grp_tree ( CREATE INDEX grp_tree_parent_idx ON permission.grp_tree (parent); CREATE TABLE permission.grp_penalty_threshold ( - id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, grp INT NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + org_unit INT NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, penalty INT NOT NULL REFERENCES config.standing_penalty (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, threshold NUMERIC(8,2) NOT NULL, CONSTRAINT penalty_grp_once UNIQUE (grp,penalty) diff --git a/Open-ILS/src/sql/Pg/100.circ_matrix.sql b/Open-ILS/src/sql/Pg/100.circ_matrix.sql index 8fc9d98f33..bb28c8e064 100644 --- a/Open-ILS/src/sql/Pg/100.circ_matrix.sql +++ b/Open-ILS/src/sql/Pg/100.circ_matrix.sql @@ -301,7 +301,7 @@ BEGIN SELECT INTO circ_test * from config.circ_matrix_test WHERE matchpoint = result.matchpoint; IF circ_test.org_depth IS NOT NULL THEN - SELECT INTO overdue_orgs ARRAY_ACCUM(id) FROM actor.org_unit_descendants( circ_ou, circ_test.org_depth ); + SELECT INTO overdue_orgs ARRAY_ACCUM(id) FROM actor.org_unit_full_path( circ_ou, circ_test.org_depth ); END IF; -- Fail if we couldn't find a set of tests @@ -324,6 +324,7 @@ BEGIN FROM actor.usr_standing_penalty usp JOIN config.standing_penalty csp ON (csp.id = usp.penalty) WHERE usr = match_user + AND usp.org_unit IN ( SELECT * FROM explode_array(overdue_orgs) ) AND csp.block_list LIKE '%RENEW%'; IF patron_penalties > 0 THEN @@ -339,6 +340,7 @@ BEGIN FROM actor.usr_standing_penalty usp JOIN config.standing_penalty csp ON (csp.id = usp.penalty) WHERE usr = match_user + AND usp.org_unit IN ( SELECT * FROM explode_array(overdue_orgs) ) AND csp.block_list LIKE '%CIRC%'; IF patron_penalties > 0 THEN @@ -406,8 +408,8 @@ BEGIN AND due_date < NOW() AND (stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE') OR stop_fines IS NULL); IF items_overdue >= max_overdue THEN - DELETE FROM actor.usr_standing_penalty WHERE usr = match_usr AND standing_penalty = 2; - INSERT INTO actor.usr_standing_penalty (usr, standing_penalty) VALUES (match_usr, 2); + DELETE FROM actor.usr_standing_penalty WHERE usr = match_usr AND standing_penalty = 2 AND org_unit = circ_ou; + INSERT INTO actor.usr_standing_penalty (usr, standing_penalty, org_unit) VALUES (match_usr, 2, circ_ou); result.fail_part := 'config.circ_matrix_test.max_overdue'; result.success := FALSE; done := TRUE; @@ -446,8 +448,8 @@ BEGIN END LOOP; IF current_fines >= max_fines THEN - DELETE FROM actor.usr_standing_penalty WHERE usr = match_usr AND standing_penalty = 1; - INSERT INTO actor.usr_standing_penalty (usr, standing_penalty) VALUES (match_usr, 1); + DELETE FROM actor.usr_standing_penalty WHERE usr = match_usr AND standing_penalty = 1 AND org_unit = circ_ou; + INSERT INTO actor.usr_standing_penalty (usr, standing_penalty, org_unit) VALUES (match_usr, 1, circ_ou); result.fail_part := 'config.circ_matrix_test.max_fines'; result.success := FALSE; RETURN NEXT result; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 404173351b..dff1b03341 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1293,12 +1293,12 @@ INSERT INTO permission.grp_tree (id, name, parent, description, perm_interval, u SELECT SETVAL('permission.grp_tree_id_seq'::TEXT, (SELECT MAX(id) FROM permission.grp_tree)); -INSERT INTO permission.grp_penalty_threshold (grp,penalty,threshold) - VALUES (1,1,10.0); -INSERT INTO permission.grp_penalty_threshold (grp,penalty,threshold) - VALUES (1,2,10.0); +INSERT INTO permission.grp_penalty_threshold (grp,org_unit,penalty,threshold) + VALUES (1,1,1,10.0); +INSERT INTO permission.grp_penalty_threshold (grp,org_unit,penalty,threshold) + VALUES (1,1,2,10.0); -SELECT SETVAL('permission.grp_tree_id_seq'::TEXT, (SELECT MAX(id) FROM permission.grp_tree)); +SELECT SETVAL('permission.grp_penalty_threshold_id_seq'::TEXT, (SELECT MAX(id) FROM permission.grp_penalty_threshold)); -- XXX Incomplete base permission setup. A patch would be appreciated. INSERT INTO permission.grp_perm_map VALUES (57, 2, 15, 0, false); -- 2.11.0