From 4caf98b7c9e44b730369d5cca21813e116a64bbe Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Sep 2025 15:05:51 +0200 Subject: [PATCH] Bug 40791: Allow choice of which Overdue messages can be patron preferences In Bug 30515, we are discussing adding a new system preference UsePatronPreferencesForOverdueNotices to let patrons control which overdue messages are sent by mail in their messaging preferences. For many libraries it would still be necessary to set a certain overdue notice (say the third overdue notice) as "mandatory for print message". On this patch we reuse the aforementioned pref and make it multivaluated with 3 values possible: Overdue1, Overdue2 and Overdue 3. Then: - if at least one is selected then patrons can edit it/them - if none selected, we don't allow the patrons to modify any Test plan: Select 2 values of the pref and confirm that it does not appear from the messaging form (staff and opac) Run the cronjob script and confirm that the patron's preferences are taken into account for the 2 values you selected. --- C4/Form/MessagingPreferences.pm | 7 ++++++ .../data/mysql/atomicupdate/bug_40791.pl | 25 +++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 2 +- .../en/includes/messaging-preference-form.inc | 3 +++ .../admin/preferences/circulation.pref | 10 ++++---- .../bootstrap/en/modules/opac-messaging.tt | 2 ++ misc/cronjobs/overdue_notices.pl | 14 +++++++---- 7 files changed, 52 insertions(+), 11 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_40791.pl diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index 36b09790990..1e66d91619a 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -74,6 +74,8 @@ sub handle_form_action { my ( $query, $target_params, $template, $insert, $categorycode ) = @_; my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); + my $patron_odue_notices = C4::Context->multivalue_preference('UsePatronPreferencesForOverdueNotices'); + # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box my $prefs_set = 0; OPTION: foreach my $option (@$messaging_options) { @@ -98,6 +100,11 @@ OPTION: foreach my $option (@$messaging_options) { } } + if ( $option->{message_name} =~ m{^Overdue} && !grep { $option->{message_name} eq $_ } @$patron_odue_notices ) { + + # If the user is not allowed to set this Overdue message we reset it + $updater->{message_transport_types} = []; + } C4::Members::Messaging::SetMessagingPreference($updater); } diff --git a/installer/data/mysql/atomicupdate/bug_40791.pl b/installer/data/mysql/atomicupdate/bug_40791.pl new file mode 100755 index 00000000000..6e8e3fe4240 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_40791.pl @@ -0,0 +1,25 @@ +use Modern::Perl; + +return { + bug_number => "40791", + description => "Make UsePatronPreferencesForOverdueNotices multi-valuated", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + my ( $UsePatronPreferencesForOverdueNotices, $type ) = $dbh->selectrow_array( + q{SELECT value, type FROM systempreferences WHERE variable='UsePatronPreferencesForOverdueNotices'}); + + if ( $type ne 'multiple' ) { + my $new_value = $UsePatronPreferencesForOverdueNotices ? q{Overdue1,Overdue2,Overdue3} : q{}; + + $dbh->do( + q{ + UPDATE systempreferences + SET value=?, options='Overdue1,Overdue2,Overdue3', explanation='Select patron specific messaging preferences for overdue notices', type='multiple' + WHERE variable="UsePatronPreferencesForOverdueNotices" + }, undef, $new_value + ); + } + }, + } diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 6906d5cae15..771159e7503 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -873,7 +873,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UseICUStyleQuotes','0','1','Tell Koha whether to use ICU style quotes ({) or default (") when tracing subjects .','YesNo'), ('UseLocationAsAQInSIP', '0', '', 'Use permanent_location instead of homebranch for AQ in SIP response', 'YesNo'), ('UseOCLCEncodingLevels','0',NULL,'If enabled, include OCLC encoding levels in leader value builder dropdown for position 17.','YesNo'), -('UsePatronPreferencesForOverdueNotices', '0', NULL, 'Use patron specific messaging preferences for overdue notices if available', 'YesNo'), +('UsePatronPreferencesForOverdueNotices', '', 'Overdue1|Overdue2|Overdue3', 'Select patron specific messaging preferences for overdue notices if available', 'multiple'), ('UseRecalls','0',NULL,'Enable or disable recalls','YesNo'), ('UseTransportCostMatrix','0','','Use Transport Cost Matrix when filling holds','YesNo'), ('UseWYSIWYGinSystemPreferences','0','','Show WYSIWYG editor when editing certain HTML system preferences.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index b5c47fa2036..6f3b048de62 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc @@ -19,12 +19,15 @@ + [% SET UsePatronPreferencesForOverdueNotices = Koha.MultivaluePreference('UsePatronPreferencesForOverdueNotices') %] [% FOREACH messaging_preference IN messaging_preferences %] [% NEXT IF !Koha.Preference( 'ILLModule' ) && messaging_preference.message_name.match('^Ill_') %] [% NEXT IF !Koha.Preference('MembershipExpiryDaysNotice') && messaging_preference.Patron_Expiry %] [% NEXT IF messaging_preference.Patron_Expiry && (category.enforce_expiry_notice || patron.category.enforce_expiry_notice) %] [% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %] [% NEXT IF !Koha.Preference('UseRecalls') && messaging_preference.message_name.match('^Recall_') %] + [% NEXT IF messaging_preference.message_name.match('^Overdue') && !UsePatronPreferencesForOverdueNotices.grep(messaging_preference.message_name).size %] + [% IF ( messaging_preference.Item_Due ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index d0aad028727..a767c45c087 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -642,12 +642,12 @@ Circulation: - "when the outstanding balance is written off." Checkin policy: - - - Use message preferences based on + - Use patron preferences for the following overdue notices: - pref: UsePatronPreferencesForOverdueNotices - choices: - 1: individual patron preference - 0: patron category - - when sending overdue notices. + multiple: + Overdue1: Overdue 1 + Overdue2: Overdue 2 + Overdue3: Overdue 3 - - pref: TrapHoldsOnOrder choices: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index d742ac60ac1..059262f0f84 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -72,12 +72,14 @@ + [% SET UsePatronPreferencesForOverdueNotices = Koha.MultivaluePreference('UsePatronPreferencesForOverdueNotices') %] [% FOREACH messaging_preference IN messaging_preferences %] [% NEXT IF !Koha.Preference( 'ILLModule' ) && messaging_preference.message_name.match('^Ill_') %] [% NEXT IF !Koha.Preference('MembershipExpiryDaysNotice') && messaging_preference.Patron_Expiry %] [% NEXT IF messaging_preference.Patron_Expiry && enforce_expiry_notice %] [% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %] [% NEXT IF !Koha.Preference('UseRecalls') && messaging_preference.message_name.match('^Recall_') %] + [% NEXT IF messaging_preference.message_name.match('^Overdue') && !UsePatronPreferencesForOverdueNotices.grep(messaging_preference.message_name).size %] [% IF ( messaging_preference.Item_Due ) %] diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 444136c4657..a4d5d5c3fed 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -749,11 +749,15 @@ END_SQL $sth2->finish; my @message_transport_types; - if ( C4::Context->preference('UsePatronPreferencesForOverdueNotices') ) { - my $patronpref = C4::Members::Messaging::GetMessagingPreferences( - { borrowernumber => $borrowernumber, message_name => "Overdue$i" } ); - if ( $patronpref && $patronpref->{'transports'} ) { - @message_transport_types = keys %{ $patronpref->{'transports'} }; + if ( my $patron_odue_notices = + C4::Context->multivalue_preference('UsePatronPreferencesForOverdueNotices') ) + { + if ( grep { "Overdue$i" eq $_ } @$patron_odue_notices ) { + my $patronpref = C4::Members::Messaging::GetMessagingPreferences( + { borrowernumber => $borrowernumber, message_name => "Overdue$i" } ); + if ( $patronpref && $patronpref->{'transports'} ) { + @message_transport_types = keys %{ $patronpref->{'transports'} }; + } } } -- 2.34.1