Bugzilla – Attachment 146551 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) Catch message preference exceptions in OPAC
Bug-18595-follow-up-Catch-message-preference-excep.patch (text/plain), 8.09 KB, created by
Lari Taskula
on 2023-02-11 14:05:13 UTC
(
hide
)
Description:
Bug 18595: (follow-up) Catch message preference exceptions in OPAC
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2023-02-11 14:05:13 UTC
Size:
8.09 KB
patch
obsolete
>From be871ce8f0e249af16c02dbbb4ad5a63b68a235c Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Thu, 5 Nov 2020 15:49:00 +0000 >Subject: [PATCH] Bug 18595: (follow-up) Catch message preference exceptions in > OPAC > >This patch handles message preference exceptions in OPAC messaging template >instead of the usual white "Internal Server Error" screen. > >To test: >0. This test plan assumes you have a default Koha installation that adds > message attributes and transports from > installer/data/mysql/mandatory/sample_notices_message_attributes.sql and > installer/data/mysql/mandatory/sample_notices_message_transports.sql > >1. Open developer tools, select console and run the following command: > >$('#email1').val('non-existing message transport type').prop('checked', true); >$('form[name=opacmessaging]').submit(); > >Observe error: >Message transport type non-existing message transport type does not exist. > >2. Open developer tools, select console and run the following command: > >$($('select[name="2-DAYS"] option')[0]).attr('value', 31); >$('form[name=opacmessaging]').submit(); > >Observe error: >Days in advance selection is out of range. The value must be between 0 and 30. > >3. Run SQL command: > >delete from message_transports where message_attribute_id=1 and is_digest=0 \ >and message_transport_type='email'; > >Open developer tools, select console and run the following command: > >$('#digest1').prop('checked', false); >$('#forcedigest1').remove(); >$('form[name=opacmessaging]').submit(); > >Observe error: >Digest must be selected for Item_Due. > >Recover your test database by running the following SQL command: > >insert into message_transports (message_attribute_id, message_transport_type, \ >is_digest, letter_module, letter_code) values (1, 'email', 0, 'circulation', \ >'DUE'); > >4. Remove your email address, open developer tools, select console and run the >following command: > >$('#email1').removeAttr('disabled'); >$('#email1').prop('checked', true); >$('form[name=opacmessaging]').submit(); > >Observe error: >You cannot select email notifications because you haven't set an email address. > >5. Remove your SMS number, open developer tools, select console and run the >following command: > >$('#sms1').removeAttr('disabled'); >$('#sms1').prop('checked', true); >$('form[name=opacmessaging]').submit(); > >Observe error: >You cannot select SMS notifications because you haven't set an SMS number address. > >6. The rest of the template error messages are currently inaccessible and >therefore untestable via GUI, but check the changes this patch introduces >manually. These exceptions are: > >Koha::Exceptions::Patron::MessagePreference::AttributeNotFound >Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable >Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable > >You can test them programmatically by searching opac-messaging.pl for the >following: > >C4::Form::MessagingPreferences::handle_form_action( ... > >and throwing each exception before it by following code: > >Koha::Exceptions::Patron::MessagePreference::AttributeNotFound->throw(); > >Sponsored-by: The National Library of Finland >--- > .../bootstrap/en/modules/opac-messaging.tt | 24 +++++++++++++++++++ > opac/opac-messaging.pl | 18 +++++++++++++- > 2 files changed, 41 insertions(+), 1 deletion(-) > >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 52388be3fc..8718418f4a 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,30 @@ > [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' ) || Koha.Preference('TranslateNotices') %] > <div id="usermessaging" class="maincontent"> > <h1>Your messaging settings</h1> >+ [% IF message_preference_exception %] >+ <div class="alert alert-danger"> >+ <h4>Error</h4> >+ [% IF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound' %] >+ <p>Message transport type <strong>[% message_preference_exception.transport_type %]</strong> does not exist.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::AttributeNotFound' %] >+ <p>Message attribute not found.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange' %] >+ <p><strong>Days in advance</strong> selection is out of range. The value must be between [% message_preference_exception.min %] and [% message_preference_exception.max %].</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable' %] >+ <p><strong>Days in advance</strong> cannot be selected for <strong>[% message_preference_exception.message_name %]</strong>.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable' %] >+ <p><strong>Digest</strong> cannot be selected for <strong>[% message_preference_exception.message_name %]</strong>.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::DigestRequired' %] >+ <p><strong>Digest</strong> must be selected for <strong>[% message_preference_exception.message_name %]</strong>.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired' %] >+ <p>You cannot select email notifications because you haven't set an email address.</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::NoTransportType' %] >+ <p>Message transport type <strong>[% message_preference_exception.transport_type %]</strong> is not available for [% message_preference_exception.message_name %].</p> >+ [% ELSIF message_preference_exception_ref == 'Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired' %] >+ <p>You cannot select SMS notifications because you haven't set an SMS number address.</p> >+ [% END %] >+ </div> >+ [% END %] > [% IF !logged_in_user.email %] > <div class="alert alert-warning"> > <h4>Cannot select email notifications</h4> >diff --git a/opac/opac-messaging.pl b/opac/opac-messaging.pl >index 4e64a4c8d1..89bfcaad95 100755 >--- a/opac/opac-messaging.pl >+++ b/opac/opac-messaging.pl >@@ -20,6 +20,8 @@ > use Modern::Perl; > > use CGI qw ( -utf8 ); >+use Scalar::Util qw( blessed ); >+use Try::Tiny; > > use C4::Auth qw( get_template_and_user ); > use C4::Context; >@@ -62,7 +64,21 @@ if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { > sms_provider_id => $sms_provider_id, > })->store; > >- C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $patron->borrowernumber }, $template); >+ try { >+ >+ C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $patron->borrowernumber }, $template); >+ >+ } catch { >+ unless ( blessed $_ && $_->can('rethrow') ) { >+ die $_; >+ } else { >+ $template->param( >+ message_preference_exception => $_, >+ message_preference_exception_ref => ref($_), # FIXME ref() does not exist in Template Toolkit, not sure if this is the best approach >+ ); >+ } >+ }; >+ > } > > if ( C4::Context->preference('TranslateNotices') ) { >-- >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