adds org unit setting for not exporting birth year and post code with aged holds... user/rogan/lp1861239_anonymize_options
authorRogan Hamby <rogan.hamby@gmail.com>
Tue, 4 Feb 2020 17:57:35 +0000 (12:57 -0500)
committerRogan Hamby <rogan.hamby@gmail.com>
Tue, 4 Feb 2020 17:58:37 +0000 (12:58 -0500)
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/xxxx.data.provide_anonymize_options_for_aged_circs_and_holds.sql [new file with mode: 0644]

index 3fb3b4a..9a4db6d 100644 (file)
@@ -313,11 +313,14 @@ UNION ALL
     FROM action.aged_circulation
 ;
 
-
-
 CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
 DECLARE
 found char := 'N';
+patron_ou               INTEGER;
+kept_year               INTEGER;
+kept_postcode           TEXT;
+donot_keep_year         BOOLEAN;
+donot_keep_postcode     BOOLEAN;
 BEGIN
 
     -- If there are any renewals for this circulation, don't archive or delete
@@ -330,7 +333,22 @@ BEGIN
 
     IF found = 'Y' THEN
         RETURN NULL;  -- don't delete
-       END IF;
+    END IF;
+
+    SELECT usr_home_ou FROM action.all_circulation WHERE id = OLD.id INTO patron_ou;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'circ.do_not_retain_year_of_birth_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_year;
+    IF donot_keep_year IS NULL THEN donot_keep_year = FALSE; END IF;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'circ.do_not_retain_post_code_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_postcode;
+    IF donot_keep_postcode IS NULL THEN donot_keep_postcode = FALSE; END IF;
+
+    IF donot_keep_year = TRUE THEN kept_year = NULL; ELSE kept_year = (SELECT usr_birth_year FROM action.all_circulation WHERE id = OLD.id); END IF;
+    IF donot_keep_postcode = TRUE THEN kept_postcode = NULL; ELSE kept_postcode = (SELECT usr_post_code FROM action.all_circulation WHERE id = OLD.id); END IF;
 
     -- Archive a copy of the old row to action.aged_circulation
 
@@ -343,7 +361,7 @@ BEGIN
         max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ,
         auto_renewal, auto_renewal_remaining)
       SELECT
-        id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        id, kept_postcode, usr_home_ou, usr_profile, kept_year, copy_call_number, copy_location,
         copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
         circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
         stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
@@ -357,7 +375,7 @@ BEGIN
     INSERT INTO money.aged_billing
         SELECT * FROM money.billing WHERE xact = OLD.id;
 
-    INSERT INTO money.aged_payment 
+    INSERT INTO money.aged_payment
         SELECT * FROM money.payment_view WHERE xact = OLD.id;
 
     DELETE FROM money.payment WHERE xact = OLD.id;
@@ -760,92 +778,63 @@ CREATE OR REPLACE VIEW action.all_hold_request AS
            behind_desk
     FROM action.aged_hold_request;
 
-CREATE OR REPLACE FUNCTION action.age_hold_on_delete () RETURNS TRIGGER AS $$
+CREATE OR REPLACE FUNCTION action.age_hold_on_delete()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $function$
 DECLARE
+patron_ou               INTEGER;
+kept_year               INTEGER;
+kept_postcode           TEXT;
+donot_keep_year         BOOLEAN;
+donot_keep_postcode     BOOLEAN;
 BEGIN
     -- Archive a copy of the old row to action.aged_hold_request
 
+    SELECT usr_home_ou FROM action.all_hold_request WHERE id = OLD.id INTO patron_ou;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'holds.do_not_retain_year_of_birth_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_year;
+    IF donot_keep_year IS NULL THEN donot_keep_year = FALSE; END IF;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'holds.do_not_retain_post_code_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_postcode;
+    IF donot_keep_postcode IS NULL THEN donot_keep_postcode = FALSE; END IF;
+
+    IF donot_keep_year = TRUE THEN kept_year = NULL; ELSE kept_year = (SELECT usr_birth_year FROM action.all_hold_request WHERE id = OLD.id); END IF;
+    IF donot_keep_postcode = TRUE THEN kept_postcode = NULL; ELSE kept_postcode = (SELECT usr_post_code FROM action.all_hold_request WHERE id = OLD.id); END IF;
+
     INSERT INTO action.aged_hold_request
-           (usr_post_code,
-            usr_home_ou,
-            usr_profile,
-            usr_birth_year,
-            staff_placed,
-            id,
-            request_time,
-            capture_time,
-            fulfillment_time,
-            checkin_time,
-            return_time,
-            prev_check_time,
-            expire_time,
-            cancel_time,
-            cancel_cause,
-            cancel_note,
-            target,
-            current_copy,
-            fulfillment_staff,
-            fulfillment_lib,
-            request_lib,
-            selection_ou,
-            selection_depth,
-            pickup_lib,
-            hold_type,
-            holdable_formats,
-            phone_notify,
-            email_notify,
-            sms_notify,
-            frozen,
-            thaw_date,
-            shelf_time,
-            cut_in_line,
-            mint_condition,
-            shelf_expire_time,
-            current_shelf_lib,
+           (usr_post_code, usr_home_ou, usr_profile, usr_birth_year,
+            staff_placed, id, request_time, capture_time,
+            fulfillment_time, checkin_time, return_time, prev_check_time,
+            expire_time, cancel_time, cancel_cause, cancel_note,
+            target, current_copy, fulfillment_staff, fulfillment_lib, 
+            request_lib, selection_ou, selection_depth, pickup_lib, 
+            hold_type, holdable_formats, phone_notify, email_notify, 
+            sms_notify, frozen, thaw_date, shelf_time, 
+            cut_in_line, mint_condition, shelf_expire_time, current_shelf_lib, 
             behind_desk)
-      SELECT 
-           usr_post_code,
-           usr_home_ou,
-           usr_profile,
-           usr_birth_year,
-           staff_placed,
-           id,
-           request_time,
-           capture_time,
-           fulfillment_time,
-           checkin_time,
-           return_time,
-           prev_check_time,
-           expire_time,
-           cancel_time,
-           cancel_cause,
-           cancel_note,
-           target,
-           current_copy,
-           fulfillment_staff,
-           fulfillment_lib,
-           request_lib,
-           selection_ou,
-           selection_depth,
-           pickup_lib,
-           hold_type,
-           holdable_formats,
-           phone_notify,
-           email_notify,
-           sms_notify,
-           frozen,
-           thaw_date,
-           shelf_time,
-           cut_in_line,
-           mint_condition,
-           shelf_expire_time,
-           current_shelf_lib,
-           behind_desk
-        FROM action.all_hold_request WHERE id = OLD.id;
+    SELECT
+            kept_postcode, usr_home_ou, usr_profile, kept_year,
+            staff_placed, id, request_time, capture_time,
+            fulfillment_time, checkin_time, return_time, prev_check_time,
+            expire_time, cancel_time, cancel_cause, cancel_note,
+            target, current_copy, fulfillment_staff, fulfillment_lib,
+            request_lib, selection_ou, selection_depth, pickup_lib,
+            hold_type, holdable_formats, phone_notify, email_notify,
+            sms_notify, frozen, thaw_date, shelf_time,
+            cut_in_line, mint_condition, shelf_expire_time, current_shelf_lib,
+            behind_desk
+    FROM action.all_hold_request WHERE id = OLD.id;
 
     RETURN OLD;
-END;
-$$ LANGUAGE 'plpgsql';
+    END;
+    $function$;
+
+COMMIT;
 
 CREATE TRIGGER action_hold_request_aging_tgr
        BEFORE DELETE ON action.hold_request
index a49cf02..0d3ff71 100644 (file)
@@ -5553,6 +5553,38 @@ INSERT into config.org_unit_setting_type
      'For staff-placed holds, in the absence of a patron preferred pickup location, fall back to using the staff workstation OU (rather than patron home OU)',
      'coust', 'description'),
    'bool', null)
+,( 'circ.do_not_retain_year_of_birth_on_aged', 'circ',
+    oils_i18n_gettext('circ.do_not_retain_year_of_birth_on_aged',
+        'When aging circulations do not retain the year from patron date of birth',
+        'cust', 'label'),
+    oils_i18n_gettext('circ.do_not_retain_year_of_birth_on_aged',
+        'When aging circulations do not retain the year from patron date of birth',
+        'cust', 'description'),
+    'bool', NULL)
+,( 'circ.do_not_retain_post_code_on_aged', 'circ',
+    oils_i18n_gettext('circ.do_not_retain_post_code_on_aged',
+        'When aging circulations do not retain the patron postal code',
+        'cust', 'label'),
+    oils_i18n_gettext('circ.do_not_retain_post_code_on_aged',
+        'When aging circulations do not retain the patron postal code',
+        'cust', 'description'),
+    'bool', NULL)
+,( 'holds.do_not_retain_year_of_birth_on_aged', 'circ',
+    oils_i18n_gettext('holds.do_not_retain_year_of_birth_on_aged',
+        'When aging holds do not retain the year from patron date of birth',
+        'cust', 'label'),
+    oils_i18n_gettext('holds.do_not_retain_year_of_birth_on_aged',
+        'When aging holds do not retain the year from patron date of birth',
+        'cust', 'description'),
+    'bool', NULL)
+,( 'holds.do_not_retain_post_code_on_aged', 'circ',
+    oils_i18n_gettext('holds.do_not_retain_post_code_on_aged',
+        'When aging holds do not retain the patron postal code',
+        'cust', 'label'),
+    oils_i18n_gettext('holds.do_not_retain_post_code_on_aged',
+        'When aging holds do not retain the patron postal code',
+        'cust', 'description'),
+    'bool', NULL
 ;
 
 UPDATE config.org_unit_setting_type
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.data.provide_anonymize_options_for_aged_circs_and_holds.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.data.provide_anonymize_options_for_aged_circs_and_holds.sql
new file mode 100644 (file)
index 0000000..bc66ad8
--- /dev/null
@@ -0,0 +1,181 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'circ.do_not_retain_year_of_birth_on_aged', 'circ',
+    oils_i18n_gettext('circ.do_not_retain_year_of_birth_on_aged',
+        'When aging circulations do not retain the year from patron date of birth',
+        'cust', 'label'),
+    oils_i18n_gettext('circ.do_not_retain_year_of_birth_on_aged',
+        'When aging circulations do not retain the year from patron date of birth',
+        'cust', 'description'),
+    'bool', NULL);
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'circ.do_not_retain_post_code_on_aged', 'circ',
+    oils_i18n_gettext('circ.do_not_retain_post_code_on_aged',
+        'When aging circulations do not retain the patron postal code',
+        'cust', 'label'),
+    oils_i18n_gettext('circ.do_not_retain_post_code_on_aged',
+        'When aging circulations do not retain the patron postal code',
+        'cust', 'description'),
+    'bool', NULL);
+
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'holds.do_not_retain_year_of_birth_on_aged', 'circ',
+    oils_i18n_gettext('holds.do_not_retain_year_of_birth_on_aged',
+        'When aging holds do not retain the year from patron date of birth',
+        'cust', 'label'),
+    oils_i18n_gettext('holds.do_not_retain_year_of_birth_on_aged',
+        'When aging holds do not retain the year from patron date of birth',
+        'cust', 'description'),
+    'bool', NULL);
+
+INSERT into config.org_unit_setting_type
+( name, grp, label, description, datatype, fm_class ) VALUES
+( 'holds.do_not_retain_post_code_on_aged', 'circ',
+    oils_i18n_gettext('holds.do_not_retain_post_code_on_aged',
+        'When aging holds do not retain the patron postal code',
+        'cust', 'label'),
+    oils_i18n_gettext('holds.do_not_retain_post_code_on_aged',
+        'When aging holds do not retain the patron postal code',
+        'cust', 'description'),
+    'bool', NULL);
+
+
+CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
+DECLARE
+found char := 'N';
+patron_ou               INTEGER;
+kept_year               INTEGER;
+kept_postcode           TEXT;
+donot_keep_year         BOOLEAN;
+donot_keep_postcode     BOOLEAN;
+BEGIN
+
+    -- If there are any renewals for this circulation, don't archive or delete
+    -- it yet.   We'll do so later, when we archive and delete the renewals.
+
+    SELECT 'Y' INTO found
+    FROM action.circulation
+    WHERE parent_circ = OLD.id
+    LIMIT 1;
+
+    IF found = 'Y' THEN
+        RETURN NULL;  -- don't delete
+    END IF;
+
+    SELECT usr_home_ou FROM action.all_circulation WHERE id = OLD.id INTO patron_ou;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'circ.do_not_retain_year_of_birth_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_year;
+    IF donot_keep_year IS NULL THEN donot_keep_year = FALSE; END IF;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'circ.do_not_retain_post_code_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_postcode;
+    IF donot_keep_postcode IS NULL THEN donot_keep_postcode = FALSE; END IF;
+
+    IF donot_keep_year = TRUE THEN kept_year = NULL; ELSE kept_year = (SELECT usr_birth_year FROM action.all_circulation WHERE id = OLD.id); END IF;
+    IF donot_keep_postcode = TRUE THEN kept_postcode = NULL; ELSE kept_postcode = (SELECT usr_post_code FROM action.all_circulation WHERE id = OLD.id); END IF;
+
+    -- Archive a copy of the old row to action.aged_circulation
+
+    INSERT INTO action.aged_circulation
+        (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ,
+        auto_renewal, auto_renewal_remaining)
+      SELECT
+        id, kept_postcode, usr_home_ou, usr_profile, kept_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ,
+        auto_renewal, auto_renewal_remaining
+        FROM action.all_circulation WHERE id = OLD.id;
+
+    -- Migrate billings and payments to aged tables
+
+    INSERT INTO money.aged_billing
+        SELECT * FROM money.billing WHERE xact = OLD.id;
+
+    INSERT INTO money.aged_payment
+        SELECT * FROM money.payment_view WHERE xact = OLD.id;
+
+    DELETE FROM money.payment WHERE xact = OLD.id;
+    DELETE FROM money.billing WHERE xact = OLD.id;
+
+    RETURN OLD;
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION action.age_hold_on_delete()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $function$
+DECLARE
+patron_ou               INTEGER;
+kept_year               INTEGER;
+kept_postcode           TEXT;
+donot_keep_year         BOOLEAN;
+donot_keep_postcode     BOOLEAN;
+BEGIN
+    -- Archive a copy of the old row to action.aged_hold_request
+
+    SELECT usr_home_ou FROM action.all_hold_request WHERE id = OLD.id INTO patron_ou;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'holds.do_not_retain_year_of_birth_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_year;
+    IF donot_keep_year IS NULL THEN donot_keep_year = FALSE; END IF;
+
+    SELECT value::BOOLEAN FROM actor.org_unit_setting WHERE name = 'holds.do_not_retain_post_code_on_aged'
+    AND org_unit IN (SELECT id FROM actor.org_unit_ancestors(patron_ou)) ORDER BY org_unit DESC LIMIT 1
+    INTO donot_keep_postcode;
+    IF donot_keep_postcode IS NULL THEN donot_keep_postcode = FALSE; END IF;
+
+    IF donot_keep_year = TRUE THEN kept_year = NULL; ELSE kept_year = (SELECT usr_birth_year FROM action.all_hold_request WHERE id = OLD.id); END IF;
+    IF donot_keep_postcode = TRUE THEN kept_postcode = NULL; ELSE kept_postcode = (SELECT usr_post_code FROM action.all_hold_request WHERE id = OLD.id); END IF;
+
+    INSERT INTO action.aged_hold_request
+           (usr_post_code, usr_home_ou, usr_profile, usr_birth_year,
+            staff_placed, id, request_time, capture_time,
+            fulfillment_time, checkin_time, return_time, prev_check_time,
+            expire_time, cancel_time, cancel_cause, cancel_note,
+            target, current_copy, fulfillment_staff, fulfillment_lib, 
+            request_lib, selection_ou, selection_depth, pickup_lib, 
+            hold_type, holdable_formats, phone_notify, email_notify, 
+            sms_notify, frozen, thaw_date, shelf_time, 
+            cut_in_line, mint_condition, shelf_expire_time, current_shelf_lib, 
+            behind_desk)
+    SELECT
+            kept_postcode, usr_home_ou, usr_profile, kept_year,
+            staff_placed, id, request_time, capture_time,
+            fulfillment_time, checkin_time, return_time, prev_check_time,
+            expire_time, cancel_time, cancel_cause, cancel_note,
+            target, current_copy, fulfillment_staff, fulfillment_lib,
+            request_lib, selection_ou, selection_depth, pickup_lib,
+            hold_type, holdable_formats, phone_notify, email_notify,
+            sms_notify, frozen, thaw_date, shelf_time,
+            cut_in_line, mint_condition, shelf_expire_time, current_shelf_lib,
+            behind_desk
+    FROM action.all_hold_request WHERE id = OLD.id;
+
+    RETURN OLD;
+    END;
+    $function$;
+
+COMMIT;
+
+