Some libraries use Template Toolkit logic to avoid sending emails. In the case of the welcome notice they may only want to send for patrons fully added, not self registered. In the case of Aspen, we currently use the patrons API for self registration as there is not a self registration API. If you add logic like: [% USE Koha %] [% IF borrower.categorycode != 'SELFREG' %] Hello [% borrower.title %] [% borrower.firstname %] [% borrower.surname %].<br> <br> Thank you for joining [% IF Koha.Preference('LibraryName') %][% Koha.Preference('LibraryName') %][% ELSE %]the library[% END %]<br> <br> You can search for all our materials in our <a href='[% Koha.Preference('OPACBaseURL') %]'>catalog</a>.<br> <br> Your library card number is [% borrower.cardnumber %]<br> <br> If you have any problems or questions regarding your account, please contact the library. [% END %] Then add a patron via the API in the self reg class: {"surname":"PATRON","firstname":"PROBLEM","library_id":"CPL","category_id":"SELFREG","email":"eample@example.org"} You get an error response: "Given does not exist"
Created attachment 179613 [details] [review] Bug 39408: Handle BadParameter exception better Currently we assume BadParameter has been thrown with a parameter that is a valid patron field. It may only include a message, or it may have come from outside the patron object, we should handle all cases. To test: 1 - Wrap "WELCOME" notice content in conditional: [% IF borrower.categorycode != 'SELFREG' %] ... [% END %] 2 - Enable preference AutoEmailNewUser 3 - Attempt to self register a patron via API with body: {"surname":"PATRON","firstname":"PROBLEM","library_id":"CPL","category_id":"SELFREG","email":"eample@example.org"} 4 - Response error: "Given does not exist" 5 - Apply this patch, restart all 6 - Repeat 3 7 - Response error: "Exception 'Koha::Exceptions::BadParameter' thrown 'Parameter message_id cannot be empty if passed.'\n" 8 - It's uglier, but actually helpful
Created attachment 179614 [details] [review] Bug 39408: Don't attempt to send a message if one is not generated The routine to create the message can return nothing if there is no content, we should handle this case and not attempt to send. To test: 1 - Test plan from last patch 2 - Apply this patch 3 - POST to patron API again 4 - Success!
Created attachment 180255 [details] [review] Bug 39408: Handle BadParameter exception better Currently we assume BadParameter has been thrown with a parameter that is a valid patron field. It may only include a message, or it may have come from outside the patron object, we should handle all cases. To test: 1 - Wrap "WELCOME" notice content in conditional: [% IF borrower.categorycode != 'SELFREG' %] ... [% END %] 2 - Enable preference AutoEmailNewUser 3 - Attempt to self register a patron via API with body: {"surname":"PATRON","firstname":"PROBLEM","library_id":"CPL","category_id":"SELFREG","email":"eample@example.org"} 4 - Response error: "Given does not exist" 5 - Apply this patch, restart all 6 - Repeat 3 7 - Response error: "Exception 'Koha::Exceptions::BadParameter' thrown 'Parameter message_id cannot be empty if passed.'\n" 8 - It's uglier, but actually helpful Signed-off-by: Claire Hernandez <claire.hernandez@biblibre.com>
Created attachment 180256 [details] [review] Bug 39408: Don't attempt to send a message if one is not generated The routine to create the message can return nothing if there is no content, we should handle this case and not attempt to send. To test: 1 - Test plan from last patch 2 - Apply this patch 3 - POST to patron API again 4 - Success! Signed-off-by: Claire Hernandez <claire.hernandez@biblibre.com>
Created attachment 182165 [details] [review] Bug 39408: Handle BadParameter exception better Currently we assume BadParameter has been thrown with a parameter that is a valid patron field. It may only include a message, or it may have come from outside the patron object, we should handle all cases. To test: 1 - Wrap "WELCOME" notice content in conditional: [% IF borrower.categorycode != 'SELFREG' %] ... [% END %] 2 - Enable preference AutoEmailNewUser 3 - Attempt to self register a patron via API with body: {"surname":"PATRON","firstname":"PROBLEM","library_id":"CPL","category_id":"SELFREG","email":"eample@example.org"} 4 - Response error: "Given does not exist" 5 - Apply this patch, restart all 6 - Repeat 3 7 - Response error: "Exception 'Koha::Exceptions::BadParameter' thrown 'Parameter message_id cannot be empty if passed.'\n" 8 - It's uglier, but actually helpful Signed-off-by: Claire Hernandez <claire.hernandez@biblibre.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Created attachment 182166 [details] [review] Bug 39408: Don't attempt to send a message if one is not generated The routine to create the message can return nothing if there is no content, we should handle this case and not attempt to send. To test: 1 - Test plan from last patch 2 - Apply this patch 3 - POST to patron API again 4 - Success! Signed-off-by: Claire Hernandez <claire.hernandez@biblibre.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Created attachment 182167 [details] [review] Bug 39408: (QA follow-up) Add unit tests Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
I applied the patches and ran yarn build. But: FAIL Koha/REST/V1/Patrons.pm FAIL tidiness File is not tidy, please run `perl misc/devel/tidy.pl Koha/REST/V1/Patrons.pm` FAIL t/db_dependent/api/v1/patrons.t FAIL critic # Subroutines::ProhibitExplicitReturnUndef: Got 1 violation(s). Please also double check the tests, I had some trouble there that only went away after a reset_all.