From: Kyle Huckins Date: Thu, 12 Jul 2018 15:40:33 +0000 (+0000) Subject: lp1777677 Test Notification Method X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6944bf6e18e37f23e37bc385754cad889d3e69a7;p=evergreen%2Fmasslnc.git 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 Signed-off-by: Terran McCanna Signed-off-by: Chris Sharp Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 21c608a532..b703f7934b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -4353,6 +4353,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 9388dbba07..9f990a3f67 100644 --- a/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql +++ b/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql @@ -58,6 +58,8 @@ INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('checkout.du 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 ('bre.edit','bre','A bib record was edited'); +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 bf1ad50675..78a8b3c14d 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -17204,6 +17204,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 dc90c7e442..724116c666 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,12 +127,14 @@ %] + [% END %] [% l("Active Barcode") %] [% ctx.user.card.barcode %] + @@ -136,11 +158,13 @@ %] + [% l("Account Creation Date") %] [% date.format(ctx.parse_datetime(ctx.user.create_date), DATE_FORMAT) %] + [% l("Account Expiration Date") %] @@ -153,6 +177,7 @@ [% END %] +
diff --git a/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 b/Open-ILS/src/templates/opac/myopac/prefs_notify.tt2 index 7b17ada0f9..346b744230 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') %]

[% IF ctx.affectedChgs %] @@ -129,7 +130,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 28b043d4ef..295ec451c1 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -148,7 +148,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 1a8bb24181..d147b45367 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -461,7 +461,10 @@ within the "form" by name for validation.
[% draw_field_label('au', 'email') %] [% draw_form_input('au', 'email', '', 'email') %] -
+
+ +
+
@@ -783,6 +786,9 @@ within the "form" by name for validation. ng-blur="handle_field_changed(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 e161105532..0d7269bac1 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; @@ -1252,10 +1264,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 }; @@ -1959,6 +1971,17 @@ function($scope , $routeParams , $q , $uibModal , $window , egCore , }); } + $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,