From 9910f72fcd03388f6735cbeb13a5b028c1c34081 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. --- C4/Form/MessagingPreferences.pm | 16 ++++++++++- .../en/includes/messaging-preference-form.inc | 27 +++++++++++++++---- .../bootstrap/en/modules/opac-messaging.tt | 20 +++++++++++--- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index 01e2892304..7cfbe4a257 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -142,6 +142,7 @@ 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 = 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 +155,22 @@ sub set_form_values { selected => $_ == $days_in_advance } } ( 0..MAX_DAYS_IN_ADVANCE ); } + + if ($option->{'transport_email'} and !$patron->email) { + $option->{'transports_email'} = 0; + $option->{'transports_email_disabled'} = 1; + } + if ($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 fd3c778356..ce873e9ddd 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,23 @@ [% USE Koha %] - +
    +[% IF !patron.email %] +
  1. +
    +

    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.

    +
    +
  2. +[% END %] +[% IF SMSSendDriver and !SMSnumber %] +
  3. +
    +

    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.

    +
    +
  4. +[% END %] +
@@ -60,7 +77,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 %] @@ -127,7 +144,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 ac959c14a3..f58b250c50 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 %] @@ -83,10 +95,10 @@ [% IF ( SMSSendDriver ) %] [% IF ( messaging_preference.transport_sms ) %]
[% ELSE %] @@ -115,10 +127,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 %]