From ac00c1e5763335333c8ea7b7d76563b9e025b69b 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 "Your user account is missing email address" and "Your user account is missing SMS number" 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 "Your user account is missing email address" 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 | 21 ++++++++++++++----- .../bootstrap/en/modules/opac-messaging.tt | 20 ++++++++++++++---- 3 files changed, 51 insertions(+), 10 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..96818d5eca 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 @@ -1,6 +1,17 @@ [% USE Koha %] - +[% IF patron && !patron.email %] +
+

Patron is missing email address

+

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

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

Patron is missing SMS number

+

Because of this you will be unable to set them SMS messaging preferences. Please see the bottom of this page and set an SMS number.

+
+[% END %] @@ -60,7 +71,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 +170,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/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index f6c62f849e..c07d366682 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 %] +
+

Your user account is missing email address

+

Because of this you will be unable to receive email notifications. Please go to your personal details and set a primary email address.

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

Your user account is missing SMS number

+

Because of this you will be unable to receive SMS notifications. Please see the bottom of this page and set an SMS number.

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

Settings updated

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