From 051afbca7eeceb0e8ebf0ba0ac8996e827f46a36 Mon Sep 17 00:00:00 2001 From: Kyle Huckins Date: Thu, 12 Jul 2018 15:40:33 +0000 Subject: [PATCH] lp1777677 Test Notification Method - Create fire_test_notification subroutine to create, fire, and return event - Add Test Notification UI buttons to preferences and patron edit screen. - Add Toast to inform of success or failure of sending test notification - Add Strings to patron interface to handle ngToast notifications - Add Test Notification to OPAC preferences UI for email and default sms number. - Abort Test Notification event if no user is found. Signed-off-by: Kyle Huckins Changes to be committed: modified: Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm modified: Open-ILS/src/sql/Pg/400.schema.action_trigger.sql modified: Open-ILS/src/sql/Pg/950.data.seed-values.sql new file: Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1777677-action-triggers-test-notification.sql modified: Open-ILS/src/templates/opac/myopac/prefs.tt2 modified: Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 new file: Open-ILS/src/templates/opac/myopac/test_notification.tt2 modified: Open-ILS/src/templates/opac/parts/header.tt2 modified: Open-ILS/src/templates/opac/parts/js.tt2 modified: Open-ILS/src/templates/staff/circ/patron/index.tt2 modified: Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 new file: Open-ILS/web/js/ui/default/opac/test_notification.js modified: Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js Signed-off-by: Terran McCanna Signed-off-by: Chris Sharp --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 19 +++++ Open-ILS/src/sql/Pg/400.schema.action_trigger.sql | 2 + Open-ILS/src/sql/Pg/950.data.seed-values.sql | 72 ++++++++++++++++++ ...lp1777677-action-triggers-test-notification.sql | 85 ++++++++++++++++++++++ Open-ILS/src/templates/opac/myopac/prefs.tt2 | 29 +++++++- .../src/templates/opac/myopac/prefs_notify.tt2 | 14 +++- .../templates/opac/myopac/test_notification.tt2 | 14 ++++ Open-ILS/src/templates/opac/parts/header.tt2 | 5 ++ Open-ILS/src/templates/opac/parts/js.tt2 | 2 +- Open-ILS/src/templates/staff/circ/patron/index.tt2 | 4 +- .../src/templates/staff/circ/patron/t_edit.tt2 | 8 +- .../web/js/ui/default/opac/test_notification.js | 21 ++++++ .../web/js/ui/default/staff/circ/patron/regctl.js | 27 ++++++- 13 files changed, 294 insertions(+), 8 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1777677-action-triggers-test-notification.sql create mode 100644 Open-ILS/src/templates/opac/myopac/test_notification.tt2 create mode 100644 Open-ILS/web/js/ui/default/opac/test_notification.js diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index d04160fe73..92f997eadd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -4333,6 +4333,25 @@ sub check_password_strength_custom { return 1; } +__PACKAGE__->register_method( + method => "fire_test_notification", + api_name => "open-ils.actor.event.test_notification" +); + +sub fire_test_notification { + my($self, $conn, $auth, $args) = @_; + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + return $e->event unless $$args{home_ou}; + return $e->die_event unless $e->allowed('UPDATE_USER', $$args{home_ou}); + + my $event_hook = $$args{event_def_type} or return $e->event; + my $usr = $e->retrieve_actor_user($$args{target}); + + return $e->event unless $usr; + + return $U->fire_object_event(undef, $event_hook, $usr, $e->requestor->ws_ou); +} __PACKAGE__->register_method( diff --git a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql index 69b365d3f8..eea2e1e705 100644 --- a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql +++ b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql @@ -57,6 +57,8 @@ INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('renewal','c INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('checkout.due.emergency_closing','aecc','Circulation due date was adjusted by the Emergency Closing handler'); INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('hold.shelf_expire.emergency_closing','aech','Hold shelf expire time was adjusted by the Emergency Closing handler'); INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('booking.due.emergency_closing','aecr','Booking reservation return date was adjusted by the Emergency Closing handler'); +INSERT INTO action_trigger.hook (key, core_type, description) VALUES ('au.email.test', 'au', 'A test email has been requested for this user'); +INSERT INTO action_trigger.hook (key, core_type, description) VALUES ('au.sms_text.test', 'au', 'A test SMS has been requested for this user'); -- and much more, I'm sure 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 a22875e4bb..d490eb6a69 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -17068,6 +17068,78 @@ INSERT INTO action_trigger.environment ( 'circ_lib' ); +INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, template) +VALUES ( + 't', 1, 'Send Test Email', 'au.email.test', 'NOOP_True', 'SendEmail', '00:01:00', +$$ +[%- USE date -%] +[%- user = target -%] +[%- lib = target.home_ou -%] +To: [%- user.email %] +From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] +Reply-To: [%- lib.email || params.sender_email || default_sender %] +Subject: Email Test Notification +Auto-Submitted: auto-generated + +Dear [% user.first_given_name %] [% user.family_name %], + +This is a test of the email associated with your account at [%- lib.name -%]. If you are receiving this message, your email information is correct. + +Sincerely, +[% lib.name %] + +Contact your library for more information: + +[% lib.name %] +[%- SET addr = lib.mailing_address -%] +[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %] +[% addr.street1 %] [% addr.street2 %] +[% addr.city %], [% addr.state %] +[% addr.post_code %] +[% lib.phone %] + +$$); +INSERT INTO action_trigger.environment (event_def, path) +VALUES (currval('action_trigger.event_definition_id_seq'), 'home_ou'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.billing_address'); + +INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, template) +VALUES ( + 't', 1, 'Send Test SMS', 'au.sms_text.test', 'NOOP_True', 'SendSMS', '00:01:00', +$$ +[%- USE date -%] +[%- user = target -%] +[%- lib = user.home_ou -%] +[%- sms_number = helpers.get_user_setting(target.id, 'opac.default_sms_notify') -%] +[%- sms_carrier = helpers.get_user_setting(target.id, 'opac.default_sms_carrier') -%] +From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +To: [%- helpers.get_sms_gateway_email(sms_carrier,sms_number) %] +Subject: Test SMS + +This is a test confirming your default SMS information at [% lib.name %]. + +Sincerely, +[% lib.name %] + +Contact your library for more information: + +[% lib.name %] +[%- SET addr = lib.mailing_address -%] +[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %] +[% addr.street1 %] [% addr.street2 %] +[% addr.city %], [% addr.state %] +[% addr.post_code %] +[% lib.phone %] + +$$); +INSERT INTO action_trigger.environment (event_def, path) +VALUES (currval('action_trigger.event_definition_id_seq'), 'home_ou'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.billing_address'); + + INSERT INTO config.org_unit_setting_type (name, grp, label, description, datatype) VALUES diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1777677-action-triggers-test-notification.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1777677-action-triggers-test-notification.sql new file mode 100644 index 0000000000..30f8364fd0 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1777677-action-triggers-test-notification.sql @@ -0,0 +1,85 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + + +INSERT into action_trigger.hook (key, core_type, description) VALUES ( + 'au.email.test', 'au', 'A test email has been requested for this user' +), +( + 'au.sms_text.test', 'au', 'A test SMS has been requested for this user' +); + +INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, template) +VALUES ( + 't', 1, 'Send Test Email', 'au.email.test', 'NOOP_True', 'SendEmail', '00:01:00', +$$ +[%- USE date -%] +[%- user = target -%] +[%- lib = target.home_ou -%] +To: [%- user.email %] +From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %] +Reply-To: [%- lib.email || params.sender_email || default_sender %] +Subject: Email Test Notification +Auto-Submitted: auto-generated + +Dear [% user.first_given_name %] [% user.family_name %], + +This is a test of the email associated with your account at [%- lib.name -%]. If you are receiving this message, your email information is correct. + +Sincerely, +[% lib.name %] + +Contact your library for more information: + +[% lib.name %] +[%- SET addr = lib.mailing_address -%] +[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %] +[% addr.street1 %] [% addr.street2 %] +[% addr.city %], [% addr.state %] +[% addr.post_code %] +[% lib.phone %] +$$); + +INSERT INTO action_trigger.environment (event_def, path) +VALUES (currval('action_trigger.event_definition_id_seq'), 'home_ou'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.billing_address'); + +INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, template) +VALUES ( + 't', 1, 'Send Test SMS', 'au.sms_text.test', 'NOOP_True', 'SendSMS', '00:01:00', +$$ +[%- USE date -%] +[%- user = target -%] +[%- lib = user.home_ou -%] +[%- sms_number = helpers.get_user_setting(target.id, 'opac.default_sms_notify') -%] +[%- sms_carrier = helpers.get_user_setting(target.id, 'opac.default_sms_carrier') -%] +From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +To: [%- helpers.get_sms_gateway_email(sms_carrier,sms_number) %] +Subject: Test SMS + +This is a test confirming your default SMS information at [% lib.name %]. + +Sincerely, +[% lib.name %] + +Contact your library for more information: + +[% lib.name %] +[%- SET addr = lib.mailing_address -%] +[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %] +[% addr.street1 %] [% addr.street2 %] +[% addr.city %], [% addr.state %] +[% addr.post_code %] +[% lib.phone %] +$$); + +INSERT INTO action_trigger.environment (event_def, path) +VALUES (currval('action_trigger.event_definition_id_seq'), 'home_ou'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address'), + (currval('action_trigger.event_definition_id_seq'), 'home_ou.billing_address'); + + +COMMIT; \ No newline at end of file diff --git a/Open-ILS/src/templates/opac/myopac/prefs.tt2 b/Open-ILS/src/templates/opac/myopac/prefs.tt2 index 74b9afb4d1..39bba393ac 100644 --- a/Open-ILS/src/templates/opac/myopac/prefs.tt2 +++ b/Open-ILS/src/templates/opac/myopac/prefs.tt2 @@ -1,7 +1,8 @@ [% PROCESS "opac/parts/header.tt2"; WRAPPER "opac/parts/myopac/prefs_base.tt2"; myopac_page = "prefs"; - prefs_page = 'prefs' %] + prefs_page = 'prefs'; + can_call_action_trigger = 'true' %]

[% l('Account Preferences') %]

@@ -23,6 +24,7 @@ ) | html %] + [% IF ctx.user.pref_first_given_name || ctx.user.pref_second_given_name || ctx.user.pref_family_name %] @@ -39,6 +41,7 @@ ) | html %] + [% END %] @@ -46,18 +49,21 @@ [% l("Day Phone") %] [% ctx.user.day_phone | html %] + [% l("Evening Phone") %] [% ctx.user.evening_phone | html %] + [% l("Other Phone") %] [% ctx.user.other_phone | html %] + @@ -66,6 +72,7 @@
[% l("Username") %] [% ctx.user.usrname | html %] + [%- IF ctx.username_change_disallowed %] [%- ELSE %] @@ -76,6 +83,7 @@ [% l("Password") %] [% l("(not shown)") %] + [%- IF disable_password_change == 'true' %] [%- ELSE %] @@ -86,6 +94,13 @@ [% l("Email Address") %] [% ctx.user.email | html %] + + [%- IF ctx.user.email %] + [% l('Send Test Email') %] + [%- END %] [%- IF disable_email_change == 'true' %] [%- ELSE %] @@ -93,7 +108,12 @@ title="[% l('Update Email Address') %]">[% l('Change') %] [%- END %] - + + + [% INCLUDE "opac/myopac/test_notification.tt2" %] + + + [% IF ctx.user.ident_value %] [% l("Primary Identification") %] @@ -107,23 +127,27 @@ %] + [% END %] [% l("Active Barcode") %] [% ctx.user.card.barcode %] + [% l("Home Library") %] [% ctx.user.home_ou.name | html %] + [% l("Account Creation Date") %] [% date.format(ctx.parse_datetime(ctx.user.create_date), DATE_FORMAT) %] + [% l("Account Expiration Date") %] @@ -136,6 +160,7 @@ [% date.format(ctx.parse_datetime(ctx.user.expire_date), DATE_FORMAT) %] + [% END %] diff --git a/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 b/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 index 47b7f72677..bbde0d8367 100644 --- a/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 +++ b/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 @@ -1,7 +1,8 @@ [% PROCESS "opac/parts/header.tt2"; WRAPPER "opac/parts/myopac/prefs_base.tt2"; myopac_page = "prefs"; - prefs_page = 'prefs_notify' %] + prefs_page = 'prefs_notify' + can_call_action_trigger = 'true' %]

[% l('Notification Preferences') %]

@@ -80,7 +81,18 @@ + [% IF ctx.user_setting_map.$setting; %] + [% l('Send Test Text Message') %]
[% l('Hint: use the full 10 digits of your phone #, no spaces, no dashes'); %] + [% END %] + + + + + [% INCLUDE "opac/myopac/test_notification.tt2" %] [% END %] diff --git a/Open-ILS/src/templates/opac/myopac/test_notification.tt2 b/Open-ILS/src/templates/opac/myopac/test_notification.tt2 new file mode 100644 index 0000000000..a092924170 --- /dev/null +++ b/Open-ILS/src/templates/opac/myopac/test_notification.tt2 @@ -0,0 +1,14 @@ +
+ [% l('Notification Sent') %] +
+
+ [% l('If you do not receive a notification, contact your Library for more information.') %] +
+ +
[% ctx.user.home_ou.name %]
+[%- IF ctx.user.home_ou.phone; %] +
[% ctx.user.home_ou.phone %]
+[%- END %] +[%- IF ctx.user.home_ou.email %] +
[% ctx.user.home_ou.email %]
+[%- END %] \ No newline at end of file diff --git a/Open-ILS/src/templates/opac/parts/header.tt2 b/Open-ILS/src/templates/opac/parts/header.tt2 index 5f397c3b7c..2bf7bb0e3c 100644 --- a/Open-ILS/src/templates/opac/parts/header.tt2 +++ b/Open-ILS/src/templates/opac/parts/header.tt2 @@ -137,6 +137,11 @@ want_dojo = 1; END; + # ... and for interfaces that require manual trigger of action triggers + IF can_call_action_trigger == 'true'; + want_dojo = 1; + END; + # Especially useful for image 'alt' tags and link title tags, # where the content may need to be unique (making it longer) # but should not exceed 75 chars for ideal screen reader support. diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 9904e3c62b..8ae6509469 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -131,7 +131,7 @@ [% INCLUDE "opac/parts/ebook_api/base_js.tt2" %] [% INCLUDE "opac/parts/ebook_api/login_js.tt2" IF (ctx.page == 'login') %] [% END %] - + diff --git a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 index eb5522e8c9..89b4f4a627 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -459,7 +459,10 @@ within the "form" by name for validation.
[% draw_field_label('au', 'email') %] [% draw_form_input('au', 'email', '', 'email') %] -
+
+ +
+
@@ -785,6 +788,9 @@ within the "form" by name for validation. ng-change="field_modified()" ng-model="user_settings['opac.default_sms_notify']" type='text'/>
+
+ +
diff --git a/Open-ILS/web/js/ui/default/opac/test_notification.js b/Open-ILS/web/js/ui/default/opac/test_notification.js new file mode 100644 index 0000000000..84ea8b4ccb --- /dev/null +++ b/Open-ILS/web/js/ui/default/opac/test_notification.js @@ -0,0 +1,21 @@ +function sendTestNotification(user_id, home_ou, event_def_type, authtoken) { + var hook = 'au.' + event_def_type + '.test'; + + var args = { + target: user_id, + home_ou: home_ou, + event_def_type: hook + }; + + new OpenSRF.ClientSession('open-ils.actor').request({ + method: 'open-ils.actor.event.test_notification', + params: [authtoken, args], + oncomplete: function(r) { + var resp = r.recv(); + if (resp) { + var banner = document.getElementById('test_notification_banner'); + banner.style.display = 'table-row'; + } + } + }).send(); +} \ No newline at end of file diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js index ae903efcc8..f3aa401428 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js @@ -656,6 +656,18 @@ angular.module('egCoreMod') }); } + service.send_test_message = function(patron, args) { + var hook = 'au.' + args.test_type + '.test'; + + return egCore.net.request( + 'open-ils.actor', + 'open-ils.actor.event.test_notification', + egCore.auth.token(), {event_def_type: hook, target: patron.id, home_ou: patron.home_ou} + ).then(function(res) { + return res; + }); + } + service.dupe_patron_search = function(patron, type, value) { var search; @@ -1251,10 +1263,10 @@ angular.module('egCoreMod') .controller('PatronRegCtrl', ['$scope','$routeParams','$q','$uibModal','$window','egCore', 'patronSvc','patronRegSvc','egUnloadPrompt','egAlertDialog', - 'egWorkLog', '$timeout', + 'egWorkLog', '$timeout','ngToast', function($scope , $routeParams , $q , $uibModal , $window , egCore , patronSvc , patronRegSvc , egUnloadPrompt, egAlertDialog , - egWorkLog, $timeout) { + egWorkLog, $timeout, ngToast) { $scope.page_data_loaded = false; $scope.hold_notify_type = { phone : null, email : null, sms : null }; @@ -1883,6 +1895,17 @@ function($scope , $routeParams , $q , $uibModal , $window , egCore , patronRegSvc.invalidate_field($scope.patron, field); } + $scope.send_test_message = function(args) { + patronRegSvc.send_test_message($scope.patron, args).then(function(res) { + if (res && res.template_output() && res.template_output().is_error() == 'f') { + ngToast.success(egCore.strings.TEST_NOTIFY_SUCCESS); + } else { + ngToast.warning(egCore.strings.TEST_NOTIFY_FAIL); + if (res) console.log(res); + } + }); + } + address_alert = function(addr) { var args = { street1: addr.street1, -- 2.11.0