From 95a63fc9da2f5763ea2de61eaa12ca0cfd1f8791 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 27 May 2021 12:16:12 +0000 Subject: [PATCH] Bug 18595: (follow-up) Disable transports if missing contact information To test: Make sure you have enabled the following system preferences: - opacuserlogin - EnhancedMessagingPreferences - EnhancedMessagingPreferencesOPAC - SMSSendDriver ---- GENERAL ---- 1. Apply patch ---- PREREQUISITES ---- 1. Select a patron to test this patch with 2. Remove patron's primary email 3. Remove patron's SMS number ---- OPAC ---- 1. Login to OPAC with your test patron. 2. Go to "your messaging" (cgi-bin/koha/opac-messaging.pl). 3. Observe two warnings "Cannot select email notifications" and "Cannot select SMS notifications" 4. See that the SMS and Email checkboxes are disabled in the messaging preferences table. 5. At the bottom of the page, set SMS number 6. Observe "Cannot select SMS notifications" gone and SMS checkboxes clickable 7. Give your test patron a primary email address 8. Refresh OPAC "your messaging" page 9. Observe all warnings are now gone and both SMS number and Email checkboxes in the messaging preferences table are clickable. 10. Set patron some messaging preferences and make sure your change applies. ---- INTRANET ---- 1. Repeat "OPAC" steps but instead of "your messaging" page, use the "Modify patron" view. Sponsored-by: The National Library of Finland --- C4/Form/MessagingPreferences.pm | 20 ++- .../prog/en/modules/members/memberentrygen.tt | 29 ++++ koha-tmpl/intranet-tmpl/prog/js/members.js | 36 +++++ .../prog/js/messaging-preference-form.js | 130 ++++++++++++++++-- .../bootstrap/en/modules/opac-messaging.tt | 22 ++- members/memberentry.pl | 26 +++- 6 files changed, 242 insertions(+), 21 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index 1affcac8e6..4653248dcb 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -141,6 +141,11 @@ sub set_form_values { my ($target_params, $template) = @_; # walk through the options and update them with these borrower_preferences my $messaging_options = Koha::Patron::MessagePreferences->get_options; + my $patron; + if ($target_params->{borrowernumber}) { + $patron = Koha::Patrons->find($target_params->{borrowernumber}); + } + PREF: foreach my $option ( @$messaging_options ) { my $pref = Koha::Patron::MessagePreferences->find( { %{ $target_params }, message_attribute_id => $option->{'message_attribute_id'} } ); $option->{ $option->{'message_name'} } = 1; @@ -153,9 +158,22 @@ sub set_form_values { selected => $_ == $days_in_advance } } ( 0..MAX_DAYS_IN_ADVANCE ); } + + if ($patron && $option->{'transport_email'} and !$patron->email) { + $option->{'transports_email'} = 0; + $option->{'transports_email_disabled'} = 1; + } + if ($patron && $option->{'transport_sms'} and !$patron->smsalertnumber) { + $option->{'transports_sms'} = 0; + $option->{'transports_sms_disabled'} = 1; + } + next unless $pref; foreach my $transport ( keys %{$pref->message_transport_types} ) { - $option->{'transports_'.$transport} = 1; + if (!$option->{'transports_'.$transport.'_disabled'}) { + $option->{'transports_'.$transport.'_disabled'} = 0; + $option->{'transports_'.$transport} = 1; + } } $option->{'digest'} = 1 if $pref->wants_digest; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 365b15600c..5fa92a7317 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1603,6 +1603,24 @@ legend:hover { + [% IF !patron || ( patron && !patron.notice_email_address ) %] +
+

Patron is missing email address

+

Because of this you will be unable to select email messaging preferences. Please modify patron and set primary email address.

+
+ [% END %] + [% IF SMSSendDriver && ( !patron || patron && !SMSnumber ) %] +
+

Patron is missing SMS number

+

Because of this you will be unable to select SMS messaging preferences. Please provide patron's SMS number first.

+
+ [% END %] + [% IF Koha.Preference('PhoneNotification') && ( !patron || patron && !patron.phone ) %] +
+

Patron is missing phone number

+

Because of this you will be unable to select phone messaging preferences. Please provide patron's phone number first.

+
+ [% END %] [% INCLUDE 'messaging-preference-form.inc' %] [% IF ( SMSSendDriver ) %] @@ -1660,6 +1678,17 @@ legend:hover { [% INCLUDE 'str/members-menu.inc' %] [% Asset.js("js/members-menu.js") | $raw %]