From 3a1bd59197a207d49bb1a2e30ce4349352b70ef2 Mon Sep 17 00:00:00 2001 From: Andrew Fuerste Henry Date: Sat, 14 Mar 2026 18:25:16 +0000 Subject: [PATCH] Bug 39781: Allow limiting of custom message notices by library To test The following should work with either email or SMS notices sent from the Add Message button in a patron record 1 - create a notice in module Patrons (custom message) for all libraries 2 - create a notice in module Patrons (custom message) for Centerville 3 - while logged in at Centerville, confirm you can see and enqueue your all libraries message 4 - while logged in at Centerville, confirm you can see but cannot successfully enqueue your Centerville message 5 - while logged in at Fairfield, confirm you can see but cannot successfully enqueue your Centerville message 6 - apply patch, restart_all 7 - while logged in at Fairfield, confirm you can see and enqueue your all libraries message 8 - while logged in at Fairfield, confirm you cannot see your Centerville message 9 - while logged in at Centervielle, confirm you can see and enqueue your Centerville message Signed-off-by: Juliet Heltibridle Signed-off-by: Martin Renvoize --- Koha/Template/Plugin/NoticeTemplates.pm | 20 +++++++++++++++++++ circ/add_message.pl | 1 + .../prog/en/includes/members-toolbar.inc | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/NoticeTemplates.pm b/Koha/Template/Plugin/NoticeTemplates.pm index b7f3d09484..8cb5545c50 100644 --- a/Koha/Template/Plugin/NoticeTemplates.pm +++ b/Koha/Template/Plugin/NoticeTemplates.pm @@ -23,6 +23,8 @@ use Template::Plugin; use base qw( Template::Plugin ); use Koha::Notice::Templates; +use C4::Context; +use C4::Letters qw( GetLettersAvailableForALibrary ); sub GetByModule { my ( $self, $module ) = @_; @@ -37,6 +39,24 @@ sub GetByModule { ); } +sub GetByModuleForLibrary { + my ( $self, $module ) = @_; + my $userenv = C4::Context->userenv; + my $branchcode = $userenv->{'branch'} // ''; + + return C4::Letters::GetLettersAvailableForALibrary( + { + branchcode => $branchcode, + module => $module, + }, + { + group_by => [ 'code', 'name' ], + columns => [ 'code', 'name' ], + order_by => ['name'] + } + ); +} + =head1 NAME Koha::Template::Plugin::NoticeTemplates - TT Plugin for notice templates diff --git a/circ/add_message.pl b/circ/add_message.pl index 2e872fbc57..c8facbd5e9 100755 --- a/circ/add_message.pl +++ b/circ/add_message.pl @@ -90,6 +90,7 @@ if ( $op eq 'cud-edit_message' && $message_id ) { letter_code => $letter_code, lang => $patron->lang, message_transport_type => $message_transport_type, + branchcode => $branchcode, tables => { 'borrowers' => $borrowernumber, 'branches' => $branchcode, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc index c7389c9ae1..cb9e31f573 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -208,7 +208,7 @@ [% END %] - [% patron_letters = NoticeTemplates.GetByModule( 'add_message' ) %] + [% patron_letters = NoticeTemplates.GetByModuleForLibrary( 'add_message' ) %] [% IF patron_letters %]