Test notification method

Bug #1777677 reported by Kathy Lussier on 2018-06-19
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Evergreen
Wishlist
Jeff Godin

Bug Description

It would be useful to have a way to easily test a patron's e-mail or SMS notification method to make sure it works.

We would like an enhancement that adds buttons in the patron editor and in the "My Account" section of the public catalog that allows staff and patrons to test their email and SMS notification.

Full requirements are available at http://masslnc.org/node/3154.

The MassLNC Evergreen Development Initiative is working with Catalyte on this enhancement.

Kyle Huckins (khuckins) on 2018-07-10
Changed in evergreen:
assignee: nobody → Kyle Huckins (khuckins)
Kyle Huckins (khuckins) wrote :

Looking for some community input here, is there any reason we don't open up the SendEmail method(and other related methods) to be usable without action triggers? I understand there may be some benefits to using action triggers when it comes to logging messages that aren't sending, but are there any other benefits to this outside of having a configurable delay(which may be useful in some cases)? My thought process here is that we could just call the API for an instant or near-instant notification, but any pushback would be welcome.

Jeff Davis (jdavis-sitka) wrote :

In theory, by using action triggers, staff can review all past or pending notifications in a single, consistent place in the client, without having to ask a system administrator.

You can also disable notifications, if necessary, by disabling the action_trigger_runner.pl --run-pending action as appropriate. This can be useful if you need to take your mail system offline temporarily, or if you have a test environment where you don't want notifications to go out. This is harder to control when EG sends emails without going through the a/t system.

At Sitka we have literally hundreds of SendEmail a/t's and we run pending events on them every 2 minutes without any trouble. That's close enough to instant for our purposes.

Bill Erickson (berick) wrote :

It's also possible to get real time A/T by calling the A/T API directly. What's more, you can tell A/T to process specific events by ID. The new code could create the test email event, then immediately tell A/T to process the event by ID. See the 'open-ils.trigger.event.fire' API.

Kyle Huckins (khuckins) wrote :

Bill,

If I'm understanding that right, we'd need to create the event, presumably using 'open-ils.trigger.event.autocreate.by_definition', and follow up by retrieving the new event's ID and calling 'open-ils.trigger.event.fire'. I'm running into an issue where calling the event.autocreate series of APIs returns a payload without a statuscode, which makes opensrf.js cranky. The APIs seem to return undef in the code. The payload does have a hash of the event's information when it goes through opensrf.js, but the event isn't created, I'm guessing because of the lack of a statuscode.

Changed in evergreen:
milestone: 3.2-beta → 3.2-rc
Kyle Huckins (khuckins) wrote :

I've pushed up a WIP branch here: http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/khuckins/lp1777677-test-notification-method

Ideally, I'd like to leverage the fire_object_event utility method, as I'm basically replicating the core aspects of it right now. The fire_test_notification method is returning as a successful event, but the osrferror log shows a severe query error when checking for the org.bounced_emails setting, where it's not finding what I'm assuming is the org id. This error also appears when I utilize fire_object_event, and I'm not entirely sure why it's not picking up the org id. I'm also unsure as to where or why this check is being made. As of now, the SQL file to create the new entries in event_hooks and event_definition are nonexistent, but the entries are present on my environment:
Hook: key: au.email.test, core_type: au, description: "A test email has been requested for a user.", passive: false
Definition: active: true, owner: 1, name: "Email Test Notification", Hook: au.email.test, Validator: NOOP_True, reactor: SendEmail, delay_interval: 00:01:00, template: https://gist.github.com/khuckins/4f8994064a3669e4d0bce8853ed675ba

The particular error I'm running into is:
2018-09-17 16:38:10 kcls-greenlandic open-ils.cstore: [ERR :32145:oils_sql.c:5898:15372022753212029] open-ils.cstore: Error with query [SELECT * FROM actor.org_unit_ancestor_setting( 'org.bounced_emails', '' ) AS "actor.org_unit_ancestor_setting" ;]: 3484946 3484946: ERROR: invalid input syntax for integer: ""
LINE 1: ....org_unit_ancestor_setting( 'org.bounced_emails', '' ) AS "a...
                                                             ^

Kyle Huckins (khuckins) wrote :

I've determined the above error was due to issues with the email template. I've since resolved those, should have some sql files pushed up soon. I've added a new commit to the branch that properly leverages $U->fire_object_event, and seems to be almost working. The issue now, I'm suspecting, is that it's not properly grabbing the org unit's email address. The patron.home_ou field doesn't seem to be fleshing, although I've attempted to manually flesh it. The event state returns as "error," though no errors appear in the logs.

Kyle Huckins (khuckins) wrote :

Additional commit made with the sql upgrade file, and my latest attempt at fleshing the target patron's home org unit. It does flesh, as evidenced by the logger lines I've placed just after fleshing, however it seems to unflesh prior to the event firing, resulting in an error related to the bounced_emails library setting(attempting to pass in target.home_ou.id when target.home_ou is the unfleshed id). If "helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails')" is removed from the from lines of the templates, the event will fire with an error state, though the output's is_error field will be false. None of the information relating to the library will be visible, and editing the template to show the value of [% lib %] will display the id.

This branch hasn't been updated to the latest master just yet, though Intend to do so before pushing the completed branch.

Changed in evergreen:
milestone: 3.2-rc → 3.2.1
Kathy Lussier (klussier) on 2018-10-03
Changed in evergreen:
milestone: 3.2.1 → 3.next
Bill Erickson (berick) wrote :

Kyle, I believe you need to add some environment variables to your new event definitions. See for example: select * from action_trigger.environment where event_def = 1;

Those define the in-template fleshing behavior. The API itself does not need to flesh the user object.

Also, the open-ils.actor.event.test_notification should check a permission (e.g. UPDATE_USER at patron->home_ou) to prevent abuse. And I suggest it exit early with $e->event if the $$args{target} does not refer to a valid user to avoid unnecessary processing.

Bill Erickson (berick) wrote :

... sanity check on $$args{event_def_type} needed as well.

Kyle Huckins (khuckins) wrote :

Thanks Bill, that helped quite a bit! As a general update on the issue's progress, I've updated the branch, and rebased to the latest master. It's still WIP, but the SMS and Email notification events are firing successfully from the patron edit screen. Next steps are to fire the action trigger event from the OPAC, and to determine where to implement the message customization.

Kyle Huckins (khuckins) wrote :

A couple updates added to the branch. I'm having some issues on the OPAC side of things, specifically with the login session being either timed out or non-existent. My guess is that it's because I'm not passing through an authtoken, but I'm not 100% on that.

This is the commit for the OPAC additions: http://git.evergreen-ils.org/?p=working/Evergreen.git;a=commitdiff;h=6b30221874caf7168613b6acfee75c3003a9c732;hp=53a0e8567f960b30a53c108ec9156e72b2c510dc

I'm wondering if anyone can take a look at the code and let me know if I'm missing anything obvious here.

Kyle Huckins (khuckins) wrote :

I was able to figure out the problem, and have since squashed and pushed my commits. So it doesn't get lost, the branch can be found here: http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/khuckins/lp1777677-test-notification-method

On the Patron Edit side of things, as long as the patron has an email address or default sms number, the notification event should created and fired when the requisite button is pressed, with a toast appearing if successful.

On the opac side, if the patron has an email address or default sms number, pressing the link next to the respective field will, on success, display a new row underneath the default mobile number/email address row, displaying a message that the notification has been sent, and containing the branch name, phone number, and email address of the patron's home org unit.

Changed in evergreen:
assignee: Kyle Huckins (khuckins) → nobody
tags: added: pullrequest
Kathy Lussier (klussier) on 2018-11-23
Changed in evergreen:
milestone: 3.next → 3.3-beta1
Kathy Lussier (klussier) wrote :

Thanks Kyle! I like the feature! I found a few issues in testing.

1. When in the patron editor, the test button immediately appears after adding an email address or SMS number for the patron. However, if the record has not yet been saved with those changes, the notification will be sent with nothing in the "To" line. Could that "Test" button only appear after the email address or SMS number has been saved to the user's record?

2. When testing the notification method in the public catalog, I was only get it to get it to work when the logged-in user was a staff user. When I was logged in with a public user Concerto account, which has fewer permissions, the action trigger event is never created. Is there a permission to this feature that would prevent it from working for public users?

3. In the public catalog, the test notification action for the SMS number is using the email test event, not the SMS test event.

4. When clicking the action to send an email or SMS test message, the screen shifts in a way that makes it difficult to see the resulting confirmation message. See https://drive.google.com/file/d/1vuNg6TX37vhNtHl8dUVYoWVvOH-fb5ri/view I think users may click the link multiple times before they realize the message was sent. I'm not sure of the best way to handle this. Maybe the confirmation could appear to the right of the email address instead of below it? Or even above the email address would make it more visible. Using red font for the confirmation message may also help.

5. I just have some suggested language changes. For the SMS message, I wouldn't use the term 'SMS' since most users don't know what this means. Maybe we could change it to say "Test text message / This is a test confirming your mobile number for [library name] is correct." For the confirmation message in the public catalog, I would prefer to see "Message Sent" instead of "Notification Sent." "If you do not receive and email message" or "If you do not receive a text message."

I could make the changes in #5 when signing off on the branch, but I'm putting the suggestions here in case the other issues aren't fixed until after I leave.

Thanks again!

Kyle Huckins (khuckins) wrote :

Thanks for the feedback Kathy! I've pushed an update to resolve issues 3 and 4, and rebased the code to the latest master. I'm currently looking into a solution for issue #1.

To address #2, currently the UPDATE_USER permission is being used. I'll take a look at the permissions currently available to a patron to see if there's a more preferred permission to use, unless there's one that's more ideal off the top of anyone's head.

Kyle Huckins (khuckins) wrote :

Another commit has been pushed addressing issue #1.

Re: Issue #2, I identified two permissions a regular user would have that initially seemed workable, OPAC_LOGIN and user_request.create. After some research it looks like user_request.create has to do with user requested acquisitions, but I'm not 100% sure on that. Does anyone in the community have any objections to using OPAC_LOGIN as a permission for this?

Jane Sandberg (sandbej) wrote :

Thanks for your work on this, Kyle. Just wanted to let you know that this feature will need some release notes as well. Here's some how-to information about release notes: https://wiki.evergreen-ils.org/doku.php?id=contributing:release_notes

tags: added: needsreleasenote
Terran McCanna (tmccanna) wrote :

Kyle - OPAC_LOGIN seems reasonable to me. I can't think of anyone that should be able to use this feature that wouldn't have that permission (at least, not in PINES).

Kyle Huckins (khuckins) wrote :

Thanks Jane and Terran. I've pushed an update resolving the 2nd and 5th issues Kathy brought up, as well as the addition of release notes, and with that, this feature should be ready for review.

tags: removed: needsreleasenote
Lucien Kress (lkress) wrote :

MassLNC testing complete, all OK from a functionality perspective.

Terran McCanna (tmccanna) wrote :

Thank you, Kyle! I was one of the testers as part of the MassLNC development initiative, so I will sign off:

I have tested this code and consent to signing off on it with my name, Terran McCanna and my email address, <email address hidden>.

tags: added: signedoff
Chris Sharp (chrissharp123) wrote :

I just removed the signedoff tag. As the "admin" user, I am able to send test SMS and Email messages as expected, but as a non-"admin" user with the required OPAC_LOGIN permission, I am prompted with a permission override box saying that I need OPAC_LOGIN to proceed.

tags: removed: signedoff
Chris Sharp (chrissharp123) wrote :

See also some IRC discussion about some recommended security improvements for this feature:

http://irc.evergreen-ils.org/evergreen/2019-01-14#i_390612

Kyle Huckins (khuckins) wrote :

Thanks for the feedback! I've pushed a new commit taking into account the recommended security improvements. It appears to work on my end when testing with the admin user and a patron user.

Terran McCanna (tmccanna) wrote :

I've tested this on 3.2.3 and unless there are any other security improvements that need resolving, I am happy to sign off:

I have tested this code and consent to signing off on it with my name, Terran McCanna and my email address, <email address hidden>.

tags: added: signedoff
tags: removed: signedoff
Terran McCanna (tmccanna) wrote :

Removing signoff because permission referenced in Actor.pm should be VIEW_USER and not USER_VIEW.

After updating that, works as expected.

Terran McCanna (tmccanna) wrote :

Also noticed that when sending the test email message from the OPAC, the on-screen confirmation message is very confusing to an end user. See screenshot.

Terran McCanna (tmccanna) wrote :

Looks like there is a typo in templates/opac/myopac/test_notification.tt2 - [% l(a'n email') %] should be [% l('an email') %].

Changed in evergreen:
assignee: nobody → Terran McCanna (tmccanna)
Terran McCanna (tmccanna) wrote :
tags: added: signedoff
Chris Sharp (chrissharp123) wrote :

Fixed-up, rebased branch with all the appropriate signoffs (including mine) located here:

https://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/csharp/lp1777677-test-notification-method

Changed in evergreen:
milestone: 3.3-beta1 → 3.3-rc
Changed in evergreen:
milestone: 3.3-rc → 3.next
Changed in evergreen:
assignee: Terran McCanna (tmccanna) → nobody
Jeff Godin (jgodin) wrote :

I think the latest branch still has at least one of the issues raised in the Jan 14 IRC conversation linked above in comment 22.

The most recent branch still appears to permit passing an arbitrary hook to OpenILS::Application::AppUtils::fire_object_event

I'll try to take a look this week.

Changed in evergreen:
assignee: nobody → Jeff Godin (jgodin)
Jeff Godin (jgodin) wrote :

Confirmed with Terran that she did not intend to remain the assignee, assigned myself.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers