Bug 35568 - Add a plugin hook to allow modification of notices created via GetPreparedLetter
Summary: Add a plugin hook to allow modification of notices created via GetPreparedLetter
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Kyle M Hall
QA Contact: Martin Renvoize
URL:
Keywords: release-notes-needed
Depends on:
Blocks:
 
Reported: 2023-12-14 11:58 UTC by Kyle M Hall
Modified: 2024-04-24 09:23 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00


Attachments
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter (6.25 KB, patch)
2023-12-14 12:09 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter (6.30 KB, patch)
2023-12-17 22:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter (6.23 KB, patch)
2024-03-04 16:38 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter (6.29 KB, patch)
2024-03-21 13:04 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall 2023-12-14 11:58:25 UTC
A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.
Comment 1 Kyle M Hall 2023-12-14 12:09:45 UTC
Created attachment 159832 [details] [review]
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter

A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t
3) Download and install the Kitchen Sink plugin v2.4.0
   https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0
4) Generate any notice or slip, such as a checkin or checkout notice
5) Note that all notices now end with "Thanks for using your local library!"
Comment 2 David Nind 2023-12-17 22:47:44 UTC
Created attachment 159932 [details] [review]
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter

A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t
3) Download and install the Kitchen Sink plugin v2.4.0
   https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0
4) Generate any notice or slip, such as a checkin or checkout notice
5) Note that all notices now end with "Thanks for using your local library!"

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2023-12-17 22:56:03 UTC
Testing notes (using KTD):

1. Added an email address for a patron (for example, Mary Burton - mary@example.com)
2. Generated notice: Patron page > More > Send welcome email

Note: With the v2.4.0 of the plugin it adds an 'I' in front of barcodes entered, so an existing barcode is never found when checking an item in or out (I'm assuming that is part of the code):
  "Check in message
   No item with barcode: I39999000011418"
Comment 4 Kyle M Hall 2024-03-04 16:38:16 UTC
Created attachment 162721 [details] [review]
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter

A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t
3) Download and install the Kitchen Sink plugin v2.4.0
   https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0
4) Generate any notice or slip, such as a checkin or checkout notice
5) Note that all notices now end with "Thanks for using your local library!"

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Martin Renvoize 2024-03-21 13:04:27 UTC
Created attachment 163614 [details] [review]
Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter

A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent.

For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t
3) Download and install the Kitchen Sink plugin v2.4.0
   https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0
4) Generate any notice or slip, such as a checkin or checkout notice
5) Note that all notices now end with "Thanks for using your local library!"

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize 2024-03-21 13:05:20 UTC
Simple hook, all working as designed and nothing contentious here.

Test present too..

Passing QA (Lets also make sure it's added to the wiki page please)
Comment 7 Katrin Fischer 2024-04-22 06:32:03 UTC
Please remember to update the wiki:
https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks
Comment 8 Katrin Fischer 2024-04-22 07:05:54 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 9 Katrin Fischer 2024-04-22 08:07:07 UTC
This appears to make a test fail - could be a merge issue?

prove t/db_dependent/Koha/Plugins/Recall_hooks.t 
t/db_dependent/Koha/Plugins/Recall_hooks.t .. 1/4 
    #   Failed test '->add_recall calls the after_recall_action hook with action add'
    #   at t/db_dependent/Koha/Plugins/Recall_hooks.t line 94.
    # found warning: Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'transform_prepared_letter called with letter content Date: 04/22/2024 08:05
    # found warning: Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'after_recall_action called with action: add, ref: Koha::Recall'
    # expected to find warning: (?^u:after_recall_action called with action: add, ref: Koha::Recall)
    # Looks like you failed 1 test of 1.
t/db_dependent/Koha/Plugins/Recall_hooks.t .. 4/4 
#   Failed test 'after_recall_action hook'
#   at t/db_dependent/Koha/Plugins/Recall_hooks.t line 99.
# Looks like you failed 1 test of 4.
t/db_dependent/Koha/Plugins/Recall_hooks.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests 

Test Summary Report
-------------------
t/db_dependent/Koha/Plugins/Recall_hooks.t (Wstat: 256 Tests: 4 Failed: 1)
  Failed test:  4
  Non-zero exit status: 1
Files=1, Tests=4,  1 wallclock secs ( 0.02 usr  0.00 sys +  1.45 cusr  0.09 csys =  1.56 CPU)
Result: FAIL
Comment 10 Martin Renvoize 2024-04-24 09:23:48 UTC
I fixed the recalls test and just pushed.. removing additional_work_needed flag.