From a51d2366a735903adf04cfe7a32af1565313b334 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 15 Sep 2022 15:43:53 -0700 Subject: [PATCH] LP1934162: add pgtap test, refreshing upgrade script Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- Open-ILS/src/sql/Pg/live_t/purge-user.pg | 34 ++++++++++++++++++++++ .../upgrade/xxxx.purge_messages_curbside_notes.sql | 9 ++++-- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/live_t/purge-user.pg diff --git a/Open-ILS/src/sql/Pg/live_t/purge-user.pg b/Open-ILS/src/sql/Pg/live_t/purge-user.pg new file mode 100644 index 0000000000..bc8e3a5454 --- /dev/null +++ b/Open-ILS/src/sql/Pg/live_t/purge-user.pg @@ -0,0 +1,34 @@ +BEGIN; + +INSERT INTO acq.invoice (id, receiver, provider, shipper, recv_method, inv_ident, closed_by) + VALUES (2222, 1, 1, 1, 'EDI', 'ABC123', 10); + +INSERT INTO action.curbside (id, patron, org, notes) + VALUES (2222, 10, 1, 'Private info'); + +INSERT INTO actor.usr_message (usr, message, sending_lib) + VALUES (10, 'Private message', 1); + +SELECT plan(3); + +SELECT * FROM actor.usr_purge_data(10, 20); + +SELECT is( + (SELECT closed_by FROM acq.invoice WHERE id = 2222)::INTEGER, + 20::INTEGER, + 'Acq invoice is now owned by dest_usr' +); + +SELECT is( + (SELECT notes FROM action.curbside WHERE id = 2222), + NULL, + 'Curbside notes are redacted' +); + +SELECT is_empty( + ('SELECT id FROM actor.usr_message WHERE usr=10 AND NOT deleted'), + 'User messages are marked as deleted' +); + +SELECT * FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.purge_messages_curbside_notes.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.purge_messages_curbside_notes.sql index 17ae225c98..a14d1e7a1a 100644 --- a/Open-ILS/src/sql/Pg/upgrade/xxxx.purge_messages_curbside_notes.sql +++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.purge_messages_curbside_notes.sql @@ -1,6 +1,5 @@ BEGIN; -SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version); CREATE OR REPLACE FUNCTION actor.usr_purge_data( src_usr IN INTEGER, @@ -18,6 +17,9 @@ BEGIN dest_usr := specified_dest_usr; END IF; + -- action_trigger.event (even doing this, event_output may--and probably does--contain PII and should have a retention/removal policy) + UPDATE action_trigger.event SET context_user = dest_usr WHERE context_user = src_usr; + -- acq.* UPDATE acq.fund_allocation SET allocator = dest_usr WHERE allocator = src_usr; UPDATE acq.lineitem SET creator = dest_usr WHERE creator = src_usr; @@ -86,13 +88,14 @@ BEGIN UPDATE actor.usr_address SET replaces = NULL WHERE usr = src_usr AND replaces IS NOT NULL; DELETE FROM actor.usr_address WHERE usr = src_usr; - DELETE FROM actor.usr_note WHERE usr = src_usr; - UPDATE actor.usr_note SET creator = dest_usr WHERE creator = src_usr; DELETE FROM actor.usr_org_unit_opt_in WHERE usr = src_usr; UPDATE actor.usr_org_unit_opt_in SET staff = dest_usr WHERE staff = src_usr; DELETE FROM actor.usr_setting WHERE usr = src_usr; DELETE FROM actor.usr_standing_penalty WHERE usr = src_usr; + UPDATE actor.usr_message SET title = 'purged', message = 'purged', read_date = NOW() WHERE usr = src_usr; + DELETE FROM actor.usr_message WHERE usr = src_usr; UPDATE actor.usr_standing_penalty SET staff = dest_usr WHERE staff = src_usr; + UPDATE actor.usr_message SET editor = dest_usr WHERE editor = src_usr; -- asset.* UPDATE asset.call_number SET creator = dest_usr WHERE creator = src_usr; -- 2.11.0