From c39abfe7e19c8ec71a61e0806bb90a85a641e633 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 30 Oct 2020 09:53:46 +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. Refresh page, observe only one warning "Cannot select email notifications" and observe the SMS checkboxes are now 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 ++++++++++++++++++- .../en/includes/messaging-preference-form.inc | 8 ++++---- .../prog/en/modules/members/memberentrygen.tt | 12 +++++++++++ .../bootstrap/en/modules/opac-messaging.tt | 20 +++++++++++++++---- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index 01e2892304..8154bd00f8 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -142,6 +142,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::Message::Preferences->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::Message::Preferences->find( { %{ $target_params }, message_attribute_id => $option->{'message_attribute_id'} } ); $option->{ $option->{'message_name'} } = 1; @@ -154,9 +159,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/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index 4ffadad1e6..874cfc4ac3 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 @@ -60,7 +60,7 @@ value="sms" disabled="disabled" /> [% END %] [% ELSE %] - [% IF ( messaging_preference.transports_sms ) %] + [% IF ( messaging_preference.transports_sms and !messaging_preference.transports_sms_disabled ) %] + value="sms" class="active_notify" data-attr-id="[% messaging_preference.message_attribute_id | html %]"[% IF messaging_preference.transports_sms_disabled %] disabled="disabled"[% END %] /> [% END %] [% END %] @@ -159,7 +159,7 @@ value="email" disabled="disabled" /> [% END %] [% ELSE %] - [% IF ( messaging_preference.transports_email ) %] + [% IF ( messaging_preference.transports_email and !messaging_preference.transports_email_disabled ) %] + value="email" class="active_notify" data-attr-id="[% messaging_preference.message_attribute_id | html %]"[% IF messaging_preference.transports_email_disabled %] disabled="disabled"[% END %] /> [% END %] [% END %] 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 2db0de5408..3f2e9b880e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1410,6 +1410,18 @@ legend:hover { + [% IF patron && !patron.email %] +
+

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 patron && SMSSendDriver and !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 %] [% INCLUDE 'messaging-preference-form.inc' %] [% IF ( SMSSendDriver ) %] 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 f6c62f849e..f4fabdf9a5 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -34,6 +34,18 @@ [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' ) %]

Your messaging settings

+ [% IF !logged_in_user.email %] +
+

Cannot select email notifications

+

Your email address is missing. We cannot send you emails before you provide your email address. Please go to your personal details to set primary email address.

+
+ [% END %] + [% IF SMSSendDriver and !SMSnumber %] +
+

Cannot select SMS notifications

+

Your SMS number is missing. We cannot send you SMS messages before you provide your SMS number. Please see the bottom of this page to set SMS number.

+
+ [% END %] [% IF ( settings_updated ) %]

Settings updated

[% END %] @@ -84,10 +96,10 @@ [% IF ( SMSSendDriver ) %] [% IF ( messaging_preference.transport_sms ) %] - [% IF ( messaging_preference.transports_sms ) %] + [% IF ( messaging_preference.transports_sms and !messaging_preference.transports_sms_disabled ) %] [% ELSE %] - + [% END %] [% ELSE %] @@ -135,10 +147,10 @@ [% IF ( messaging_preference.transport_email ) %] - [% IF ( messaging_preference.transports_email ) %] + [% IF ( messaging_preference.transports_email and !messaging_preference.transports_email_disabled ) %] [% ELSE %] - + [% END %] [% ELSE %] -- 2.17.1