From d0acd1e63c2571bce868253d6c2873e5861ac5f8 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 14 May 2020 14:13:38 -0400 Subject: [PATCH] LP#1860703: Additional A/T hooks for use with various patron changes This commit normalizes the au.update/au.updated and au.create/au.created hooks, making them match between code and seed data, and adds two entirely new hooks, au.renewed and au.barcode_changed. Signed-off-by: Mike Rylander Signed-off-by: Troy Leonard Signed-off-by: Galen Charlton --- .../perlmods/lib/OpenILS/Application/Actor.pm | 26 ++++++++++++++++--- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 9 +++++++ .../Pg/upgrade/YYYY.new_user_a-t_hooks.sql | 26 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/YYYY.new_user_a-t_hooks.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index d04160fe73..21c608a532 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -480,6 +480,7 @@ sub update_patron { my $old_patron; my $barred_hook = ''; + my $renew_hook = ''; if($patron->isnew()) { ( $new_patron, $evt ) = _add_patron($e, _clone_patron($patron)); @@ -495,6 +496,8 @@ sub update_patron { $old_patron = $e->retrieve_actor_user($patron->id) or return $e->die_event; + $renew_hook = 'au.renewed' if ($old_patron->expire_date ne $new_patron->expire_date); + if($U->is_true($old_patron->barred) != $U->is_true($new_patron->barred)) { my $perm = $U->is_true($old_patron->barred) ? 'UNBAR_PATRON' : 'BAR_PATRON'; return $e->die_event unless $e->allowed($perm, $patron->home_ou); @@ -546,10 +549,13 @@ sub update_patron { my $tses = OpenSRF::AppSession->create('open-ils.trigger'); if($patron->isnew) { $tses->request('open-ils.trigger.event.autocreate', - 'au.create', $new_patron, $new_patron->home_ou); + 'au.created', $new_patron, $new_patron->home_ou); } else { $tses->request('open-ils.trigger.event.autocreate', - 'au.update', $new_patron, $new_patron->home_ou); + 'au.updated', $new_patron, $new_patron->home_ou); + + $tses->request('open-ils.trigger.event.autocreate', $renew_hook, + $new_patron, $new_patron->home_ou) if $renew_hook; $tses->request('open-ils.trigger.event.autocreate', $barred_hook, $new_patron, $new_patron->home_ou) if $barred_hook; @@ -916,6 +922,7 @@ sub _add_update_cards { my $virtual_id; #id of the card before creation + my $card_changed = 0; my $cards = $patron->cards(); for my $card (@$cards) { @@ -932,13 +939,18 @@ sub _add_update_cards { $new_patron->card($card->id()); $new_patron->ischanged(1); } + $card_changed++; } elsif( ref($card) and $card->ischanged() ) { $evt = _update_card($e, $card); return (undef, $evt) if $evt; + $card_changed++; } } + $U->create_events_for_hook('au.barcode_changed', $new_patron, $e->requestor->ws_ou) + if $card_changed; + return ( $new_patron, undef ); } @@ -1565,6 +1577,7 @@ sub update_passwd { return new OpenILS::Event('INCORRECT_PASSWORD'); } + my $at_event = 0; if( $api =~ /password/o ) { # NOTE: with access to the plain text password we could crypt # the password without the extra MD5 pre-hashing. Other changes @@ -1587,15 +1600,20 @@ sub update_passwd { return new OpenILS::Event('USERNAME_EXISTS'); } $db_user->usrname($new_val); + $at_event++; } elsif( $api =~ /email/o ) { $db_user->email($new_val); + $at_event++; } } $e->update_actor_user($db_user) or return $e->die_event; $e->commit; + $U->create_events_for_hook('au.updated', $db_user, $e->requestor->ws_ou) + if $at_event; + # update the cached user to pick up these changes $U->simplereq('open-ils.auth', 'open-ils.auth.session.reset_timeout', $auth, 1); return 1; @@ -3617,8 +3635,8 @@ sub update_user_pending_address { my $e = new_editor(authtoken => $auth, xact => 1); return $e->die_event unless $e->checkauth; + my $user = $e->retrieve_actor_user($addr->usr) or return $e->die_event; if($addr->usr != $e->requestor->id) { - my $user = $e->retrieve_actor_user($addr->usr) or return $e->die_event; return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou); } @@ -3631,6 +3649,8 @@ sub update_user_pending_address { } $e->commit; + $U->create_events_for_hook('au.updated', $user, $e->requestor->ws_ou); + return $addr->id; } 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 7100beac66..7d6ed61555 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -16609,6 +16609,15 @@ INSERT INTO action_trigger.environment (event_def, path) VALUES INSERT INTO action_trigger.hook (key, core_type, description, passive) VALUES ('au.created', 'au', 'A user was created', 't'); +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.updated', 'au', 'A user was updated', 't'); + +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.barcode_changed', 'au', 'A card was updated or created for an existing user', 't'); + +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.renewed', 'au', 'A user was renewed by having their expire date changed', 't'); + --SQL to create event definition for new account creation notice --Inactive, owned by top of org tree by default. Modify to suit needs. diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.new_user_a-t_hooks.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.new_user_a-t_hooks.sql new file mode 100644 index 0000000000..8857cd19f2 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.new_user_a-t_hooks.sql @@ -0,0 +1,26 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +-- First, normalize the au.create[d] and au.update[d] hooks. The code and seed data differ. + +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.created', 'au', 'A user was created', 't') ON CONFLICT DO NOTHING; +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.updated', 'au', 'A user was updated', 't') ON CONFLICT DO NOTHING; + + +UPDATE action_trigger.event_definition SET hook = 'au.created' WHERE hook = 'au.create'; +UPDATE action_trigger.event_definition SET hook = 'au.updated' WHERE hook = 'au.update'; + +DELETE FROM action_trigger.hook WHERE key = 'au.create'; +DELETE FROM action_trigger.hook WHERE key = 'au.update'; + +-- Now the entirely new ones... +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.renewed', 'au', 'A user was renewed by having their expire date changed', 't'); + +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('au.barcode_changed', 'au', 'A card was updated or created for an existing user', 't'); + +COMMIT; -- 2.43.2