From ffb1d58274054fb56e1a4dcdd877beecca350f7d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 27 Dec 2012 10:58:01 -0500 Subject: [PATCH] Action/trigger user barred/unbarred hooks New active A/T hooks 'au.barred' and 'au.unbarred', plus PatronBarred and PatronNotBarred validators, plus code to make the hooks dance. Signed-off-by: Bill Erickson Conflicts: Open-ILS/src/sql/Pg/950.data.seed-values.sql Signed-off-by: Mike Rylander --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 7 ++++ .../lib/OpenILS/Application/Trigger/Validator.pm | 10 +++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 40 ++++++++++++++++++++ .../sql/Pg/upgrade/XXXX.data.user_barred_hook.sql | 44 ++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.user_barred_hook.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 5f6073fa4b..d818454d14 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -373,6 +373,7 @@ sub update_patron { # if we want to represent the old patron. my $old_patron; + my $barred_hook = ''; if($patron->isnew()) { ( $new_patron, $evt ) = _add_patron($session, _clone_patron($patron), $user_obj); @@ -392,6 +393,9 @@ sub update_patron { if($U->is_true($old_patron->barred) != $U->is_true($new_patron->barred)) { $evt = $U->check_perms($user_obj->id, $patron->home_ou, $U->is_true($old_patron->barred) ? 'UNBAR_PATRON' : 'BAR_PATRON'); return $evt if $evt; + + $barred_hook = $U->is_true($new_patron->barred) ? + 'au.barred' : 'au.unbarred'; } } @@ -429,6 +433,9 @@ sub update_patron { $tses->request('open-ils.trigger.event.autocreate', 'au.create', $new_patron, $new_patron->home_ou); } else { $tses->request('open-ils.trigger.event.autocreate', 'au.update', $new_patron, $new_patron->home_ou); + + $tses->request('open-ils.trigger.event.autocreate', $barred_hook, + $new_patron, $new_patron->home_ou) if $barred_hook; } return flesh_user($new_patron->id(), new_editor(requestor => $user_obj, xact => 1)); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm index f3a701a22c..6b5dc3c399 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm @@ -151,4 +151,14 @@ sub HoldNotifyCheck { return 1; } +# core_type au +sub PatronBarred { + my ($self, $env) = @_; + return $U->is_true($env->{target}->barred); +} + +sub PatronNotBarred { + return !PatronBarred(@_); +} + 1; 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 3beb825d67..04fd4e0754 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -12528,3 +12528,43 @@ INSERT INTO actor.org_unit_setting ( '"6 months"' ); +INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'au.barred', + 'au', + 'A user was barred by staff', + FALSE + ); + +INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'au.unbarred', + 'au', + 'A user was un-barred by staff', + FALSE + ); + +INSERT INTO action_trigger.validator ( + module, + description + ) VALUES ( + 'PatronBarred', + 'Tests if a patron is currently marked as barred' + ); + +INSERT INTO action_trigger.validator ( + module, + description + ) VALUES ( + 'PatronNotBarred', + 'Tests if a patron is currently not marked as barred' + ); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.user_barred_hook.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.user_barred_hook.sql new file mode 100644 index 0000000000..20ea301432 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.user_barred_hook.sql @@ -0,0 +1,44 @@ + +BEGIN; + +INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'au.barred', + 'au', + 'A user was barred by staff', + FALSE + ); + +INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'au.unbarred', + 'au', + 'A user was un-barred by staff', + FALSE + ); + +INSERT INTO action_trigger.validator ( + module, + description + ) VALUES ( + 'PatronBarred', + 'Tests if a patron is currently marked as barred' + ); + +INSERT INTO action_trigger.validator ( + module, + description + ) VALUES ( + 'PatronNotBarred', + 'Tests if a patron is currently not marked as barred' + ); + +COMMIT; -- 2.11.0