Bugzilla – Attachment 146550 Details for
Bug 18595
Move C4::Members::Messaging to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18595: (follow-up) Disable transports if missing contact information
Bug-18595-follow-up-Disable-transports-if-missing-.patch (text/plain), 21.90 KB, created by
Lari Taskula
on 2023-02-11 14:05:09 UTC
(
hide
)
Description:
Bug 18595: (follow-up) Disable transports if missing contact information
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2023-02-11 14:05:09 UTC
Size:
21.90 KB
patch
obsolete
>From 95a63fc9da2f5763ea2de61eaa12ca0cfd1f8791 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >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 { > <div id="messaging_prefs_loading" class="form-message" style="display:none"> > <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading new messaging defaults > </div> >+ [% IF !patron || ( patron && !patron.notice_email_address ) %] >+ <div class="dialog message missing-message-pref-contact"> >+ <h4>Patron is missing email address</h4> >+ <p>Because of this you will be unable to select email messaging preferences. Please <a href="memberentry.pl?op=modify&borrowernumber=[% patron.borrowernumber %]">modify patron</a> and set primary email address.</p> >+ </div> >+ [% END %] >+ [% IF SMSSendDriver && ( !patron || patron && !SMSnumber ) %] >+ <div class="dialog message missing-message-pref-contact"> >+ <h4>Patron is missing SMS number</h4> >+ <p>Because of this you will be unable to select SMS messaging preferences. Please provide patron's SMS number first.</p> >+ </div> >+ [% END %] >+ [% IF Koha.Preference('PhoneNotification') && ( !patron || patron && !patron.phone ) %] >+ <div class="dialog message missing-message-pref-contact"> >+ <h4>Patron is missing phone number</h4> >+ <p>Because of this you will be unable to select phone messaging preferences. Please provide patron's phone number first.</p> >+ </div> >+ [% END %] > <input type="hidden" name="setting_messaging_prefs" value="1" /> > [% 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 %] > <script> >+ auto_email_primary_address = "[% Koha.Preference('AutoEmailPrimaryAddress') %]"; >+ [% IF patron.notice_email_address %] >+ patron_email = "[% patron.notice_email_address %]"; >+ [% END %] >+ [% IF patron.phone %] >+ patron_phone = "[% patron.phone %]"; >+ [% END %] >+ [% IF patron.smsalertnumber %] >+ patron_sms = "[% patron.smsalertnumber %]"; >+ [% END %] >+ > function update_cardnumber_warning(size){ > var max_len = [% maxlength_cardnumber | html %]; > if ( size >= max_len ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js >index 597bb5d141..f082aa95ff 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/members.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/members.js >@@ -293,4 +293,40 @@ $(document).ready(function(){ > "right": "1%", > "width": "150px", > } ); >+ >+ auto_email_primary_address_el = $("input#email"); >+ if ((typeof auto_email_primary_address !== "undefined")) { >+ if (auto_email_primary_address === "OFF") { >+ auto_email_primary_address_el = $("input#email,input#emailpro,input#B_email"); >+ } else { >+ auto_email_primary_address_el = $("input#"+auto_email_primary_address); >+ } >+ } >+ >+ if ((typeof patron_email !== "undefined" && !patron_email) || auto_email_primary_address_el.length ) { >+ auto_email_primary_address_el.each(function () { >+ if (disableCheckboxesWithInvalidPreferences($(this), "email")) { >+ return false; >+ } >+ }); >+ } >+ if ((typeof patron_phone !== "undefined" && !patron_phone) || $("input#phone").length) { >+ disableCheckboxesWithInvalidPreferences($("input#phone"), "phone"); >+ } >+ if ((typeof patron_sms !== "undefined" && !patron_sms) || $("input#SMSnumber").length) { >+ disableCheckboxesWithInvalidPreferences($("input#SMSnumber"), "sms"); >+ } >+ auto_email_primary_address_el.on("input change", function() { >+ auto_email_primary_address_el.each(function () { >+ if (disableCheckboxesWithInvalidPreferences($(this), "email")) { >+ return false; >+ } >+ }); >+ }); >+ $("input#phone").on("input change", function() { >+ disableCheckboxesWithInvalidPreferences($("input#phone"), "phone"); >+ }); >+ $("input#SMSnumber").on("input change", function() { >+ disableCheckboxesWithInvalidPreferences($("input#SMSnumber"), "sms"); >+ }); > }); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js >index 65e4379adf..f8ba138ff5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js >@@ -54,19 +54,6 @@ $(document).ready(function(){ > }); > } > >- function toggle_digest(id){ >- let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false; >- if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) { >- if ($("#forcedigest"+id).length === 0) { >- $("#digest"+id).attr("disabled", false).tooltip('disable'); >- } >- } else { >- if ($("#forcedigest"+id).length === 0) { >- $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); >- } >- } >- >- } > // At load time, we want digest disabled if no digest using transport is enabled > $(".pmp_email").each(function(){ > toggle_digest(Number($(this).attr("id").replace("email", ""))); >@@ -85,3 +72,120 @@ $(document).ready(function(){ > > // $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip(); > }); >+ >+function toggle_digest(id){ >+ let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false; >+ if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) { >+ if ($("#forcedigest"+id).length === 0) { >+ $("#digest"+id).attr("disabled", false).tooltip('disable'); >+ >+ } >+ } else { >+ if ($("#forcedigest"+id).length === 0) { >+ $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); >+ } >+ } >+ >+} >+ >+var patron_messaging_checkbox_preferences = { >+ email: { >+ checked_checkboxes: null, >+ is_enabled: true, >+ disabled_checkboxes: null >+ }, >+ sms: { >+ checked_checkboxes: null, >+ is_enabled: true, >+ disabled_checkboxes: null >+ }, >+ phone: { >+ checked_checkboxes: null, >+ is_enabled: true, >+ disabled_checkboxes: null >+ }, >+}; >+ >+function disableCheckboxesWithInvalidPreferences(elem, id_attr) { >+ >+ if (!$(elem).length && typeof window["patron_" + id_attr] !== "undefined") { >+ return; >+ } >+ >+ // Get checkbox preferences for the element >+ var checkbox_prefs = patron_messaging_checkbox_preferences[id_attr]; >+ >+ // Check if element is empty or not valid >+ if (!$(elem).length || $(elem).val().length == 0 || !$(elem).valid()) { >+ >+ if (checkbox_prefs.is_enabled) { >+ >+ if ($("input[type='checkbox'][id^=" + id_attr + "]").length === 0) { >+ return; >+ } >+ >+ // Save the state of checked checkboxes >+ checkbox_prefs.checked_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:checked,input[type='checkbox'][id^=digest]:checked"); >+ >+ // Clear patron messaging preferences checkboxes >+ $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("checked"); >+ >+ // Then disable checkboxes from patron messaging perferences >+ $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", "disabled"); >+ >+ // Color table cell's background emphasize the disabled state of the checkbox >+ $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#E8F0F8"); >+ >+ disable_digest = true; >+ $.each(patron_messaging_checkbox_preferences, function(key, obj) { >+ if (key === id_attr) { >+ return; >+ } >+ if ($("input[type='checkbox'][id^=" + key + "]:not(:disabled)").length) { >+ disable_digest = false; >+ } >+ }); >+ >+ if (disable_digest) { >+ $("input[type='checkbox'][id^=digest]").removeAttr("checked"); >+ $("input[type='checkbox'][id^=digest]").prop("disabled", "disabled"); >+ $("input[type='checkbox'][id^=digest]").parent().css("background-color", "#E8F0F8"); >+ } >+ >+ // Remove notification of missing contact >+ $("div.missing-message-pref-contact").css("display", "block"); >+ >+ checkbox_prefs.is_enabled = false; >+ } >+ >+ return false; >+ >+ } else { >+ >+ if (!checkbox_prefs.is_enabled) { >+ // Enable patron messaging preferences checkboxes >+ $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", false); >+ >+ $("input[type='checkbox'][id^=digest]").parent().css("background-color", ""); >+ >+ // Restore the state of checkboxes >+ checkbox_prefs.checked_checkboxes.each(function() { >+ $(this).prop("checked", "checked"); >+ if (!$("input[type='checkbox'][id='digest"+$(this).attr("data-attr-id")+"']:checked").length === 0) { >+ toggle_digest($(this).attr("data-attr-id")); >+ } >+ }); >+ >+ // Remove the background color from table cell >+ $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", ""); >+ >+ // Remove notification of missing contact >+ $("div.missing-message-pref-contact").css("display", "none"); >+ >+ checkbox_prefs.is_enabled = true; >+ } >+ >+ return true; >+ >+ } >+} >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 b3c956bc21..52388be3fc 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt >@@ -37,6 +37,18 @@ > [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' ) || Koha.Preference('TranslateNotices') %] > <div id="usermessaging" class="maincontent"> > <h1>Your messaging settings</h1> >+ [% IF !logged_in_user.email %] >+ <div class="alert alert-warning"> >+ <h4>Cannot select email notifications</h4> >+ <p>Your email address is missing. We cannot send you emails before you provide your email address. Please go to <a href="opac-memberentry.pl">your personal details</a> to set primary email address.</p> >+ </div> >+ [% END %] >+ [% IF SMSSendDriver and !SMSnumber %] >+ <div class="alert alert-warning"> >+ <h4>Cannot select SMS notifications</h4> >+ <p>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.</p> >+ </div> >+ [% END %] > [% IF ( settings_updated ) %] > <div class="alert alert-success"><p><strong>Settings updated</strong></p></div> > [% END %] >@@ -95,10 +107,10 @@ > [% IF ( SMSSendDriver ) %] > [% IF ( messaging_preference.transport_sms ) %] > <td class="selectcol"> >- [% IF ( messaging_preference.transports_sms ) %] >+ [% IF ( messaging_preference.transports_sms and !messaging_preference.transports_sms_disabled ) %] > <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms" checked="checked" /> > [% ELSE %] >- <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms" /> >+ <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms"[% IF messaging_preference.transports_sms_disabled %] disabled="disabled"[% END %] /> > [% END %] > </td> > [% ELSE %] >@@ -150,10 +162,10 @@ > > [% IF ( messaging_preference.transport_email ) %] > <td class="selectcol"> >- [% IF ( messaging_preference.transports_email ) %] >- <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" checked="checked" /> >+ [% IF ( messaging_preference.transports_email and !messaging_preference.transports_email_disabled ) %] >+ <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" checked="checked" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id | html %].checked=false;" /> > [% ELSE %] >- <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" /> >+ <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id | html %].checked=false;"[% IF messaging_preference.transports_email_disabled %] disabled="disabled"[% END %] /> > [% END %] > </td> > [% ELSE %] >diff --git a/members/memberentry.pl b/members/memberentry.pl >index 0193cc3777..3d800ed77e 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -23,6 +23,8 @@ use Modern::Perl; > > # external modules > use CGI qw ( -utf8 ); >+use Scalar::Util qw( blessed ); >+use Try::Tiny; > > # internal modules > use C4::Auth qw( get_template_and_user haspermission ); >@@ -479,7 +481,17 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ > } > > if ( $patron && (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) ) { >- C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'}); >+ try { >+ C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'}); >+ } catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ die $_; >+ } else { >+ $template->param( >+ error_alert => $_ >+ ); >+ } >+ }; > } > > # Create HouseboundRole if necessary. >@@ -560,7 +572,17 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ > > add_guarantors( $patron, $input ); > if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { >- C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); >+ try { >+ C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); >+ } catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ die $_; >+ } else { >+ $template->param( >+ error_alert => $_ >+ ); >+ } >+ }; > } > } > } >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18595
:
63435
|
63436
|
63437
|
63438
|
63439
|
63440
|
63441
|
63794
|
63795
|
63796
|
63797
|
63798
|
63799
|
63800
|
63813
|
63815
|
63816
|
63817
|
63818
|
63819
|
63820
|
63821
|
63822
|
63823
|
63824
|
63825
|
63826
|
63827
|
63828
|
63829
|
69441
|
69442
|
69443
|
69444
|
69445
|
69446
|
69447
|
69448
|
69449
|
69450
|
69451
|
69452
|
69453
|
69667
|
69668
|
69669
|
69670
|
69671
|
69672
|
69673
|
69674
|
93873
|
93874
|
93875
|
93876
|
93877
|
93878
|
93879
|
93880
|
93908
|
94753
|
94754
|
103444
|
103445
|
103446
|
103447
|
103448
|
103449
|
103450
|
103451
|
103452
|
110151
|
110152
|
110153
|
110154
|
110155
|
110156
|
110157
|
110158
|
110159
|
112147
|
112148
|
112149
|
112150
|
112151
|
112152
|
112153
|
112154
|
112155
|
112690
|
113126
|
113192
|
113221
|
113222
|
113769
|
146541
|
146542
|
146543
|
146544
|
146545
|
146546
|
146547
|
146548
|
146549
| 146550 |
146551
|
146552