beginning the org_unit-ification of penalties
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Nov 2008 22:10:07 +0000 (22:10 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Nov 2008 22:10:07 +0000 (22:10 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11292 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/006.schema.permissions.sql
Open-ILS/src/sql/Pg/100.circ_matrix.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql

index 08c2981..0ca7d71 100644 (file)
@@ -1725,10 +1725,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="grp" oils_obj:array_position="4" oils_persist:virtual="false"  reporter:datatype="link"/>
                        <field name="penalty" oils_obj:array_position="5" oils_persist:virtual="false"  reporter:datatype="link"/>
                        <field name="threshold" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="float"/>
+                       <field name="org_unit" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="penalty" reltype="has_a" key="id" map="" class="csp"/>
                        <link field="grp" reltype="has_a" key="id" map="" class="pgt"/>
+                       <link field="org_unit" reltype="has_a" key="id" map="" class="aou"/>
         </links>
        </class>
        <class id="ccs" controller="open-ils.cstore" oils_obj:fieldmapper="config::copy_status" oils_persist:tablename="config.copy_status">
@@ -1761,9 +1763,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="usr" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="link"/>
                        <field name="staff" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="link"/>
                        <field name="standing_penalty" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="link"/>
+                       <field name="org_unit" oils_obj:array_position="8" oils_persist:virtual="false" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="org_unit" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="staff" reltype="has_a" key="id" map="" class="au"/>
                        <link field="standing_penalty" reltype="has_a" key="id" map="" class="csp"/>
                </links>
index 5a105c9..ceef438 100644 (file)
@@ -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 <mrylander@gmail.com>
- *
- * 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 <mrylander@gmail.com>
+ *
+ * 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;
index 99f8cbc..e3a85ba 100644 (file)
@@ -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)
index 8fc9d98..bb28c8e 100644 (file)
@@ -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;
index 4041733..dff1b03 100644 (file)
@@ -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);