Bugzilla – Attachment 96819 Details for
Bug 20930
Validate and cache parsed YAML/JSON type system preferences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20930: Display human readable errors in preferences page
Bug-20930-Display-human-readable-errors-in-prefere.patch (text/plain), 6.10 KB, created by
Michal Denar
on 2020-01-04 20:49:29 UTC
(
hide
)
Description:
Bug 20930: Display human readable errors in preferences page
Filename:
MIME Type:
Creator:
Michal Denar
Created:
2020-01-04 20:49:29 UTC
Size:
6.10 KB
patch
obsolete
>From f1dcd2c26e2bbcff617958f2fe570adf18ee1e5b Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Mon, 25 Jun 2018 17:20:44 +0300 >Subject: [PATCH] Bug 20930: Display human readable errors in preferences page > >Displays human readable error when YAML/JSON preference has invalid syntax. > >If multiple preferences are modified at the same time, notifies librarian of the >preferences that were saved and the ones that had errors. > >To test: >1. Apply patches >2. Write invalid YAML syntax to OpacHiddenItems system preference >3. Observe "Error; Preference OpacHiddenItems has invalid syntax" error > You should also receive a hint on line and column numbers of where > the error occured. >4. Write valid YAML syntax to OpacHiddenItems system preference >5. Observe "Saved preference OpacHiddenItems" message >6. Test steps 2-5 for both single preference modification and together > with other system preferences. > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Michal Denar <black23@gmail.com> >--- > .../prog/en/modules/admin/preferences.tt | 3 ++- > .../intranet-tmpl/prog/js/pages/preferences.js | 25 ++++++++++++++++- > svc/config/systempreferences | 31 +++++++++++++++++++--- > 3 files changed, 54 insertions(+), 5 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >index 764f1645d9..920f59f77e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >@@ -211,7 +211,8 @@ > var MSG_LOADING = _( "Loading..." ); > var MSG_ALL_VALUE_WARN = _("Note: _ALL_ value will override all other values"); > var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:"); >- var MSG_INVALID = _( "Error: presence of invalid data prevent saving. Please make the corrections and try again." ); >+ var MSG_INVALID = _( "Error: presence of invalid data prevents saving. Please make the corrections and try again." ); >+ var MSG_INVALID_SYNTAX = _( "Error: Preference '%s' has invalid syntax" ); > </script> > [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] > [% Asset.js("js/ajax.js") | $raw %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >index d5db030e7b..43ee090c34 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >@@ -30,7 +30,8 @@ KOHA.Preferences = { > data: data, > url: '/cgi-bin/koha/svc/config/systempreferences/', > success: function ( data ) { KOHA.Preferences.Success( form ) }, >- complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) } >+ complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }, >+ error: function( data ) { KOHA.Preferences.Error( data ) } > } ); > }, > Success: function ( form ) { >@@ -46,6 +47,28 @@ KOHA.Preferences = { > .find( '.modified-warning' ).remove().end() > .find( '.modified' ).removeClass('modified'); > KOHA.Preferences.Modified = false; >+ }, >+ Error: function ( form ) { >+ msg = "<strong>"+ MSG_DATA_NOT_SAVED + "</strong>\n"; >+ modified_prefs.each(function(){ >+ var modified_pref = $(this).attr("id"); >+ modified_pref = modified_pref.replace("pref_",""); >+ if (modified_pref in form.sysprefs) { >+ if (form.sysprefs[modified_pref].error === 'Koha::Exceptions::Config::InvalidSyntax') { >+ msg += "<strong>"+ MSG_INVALID_SYNTAX.format(modified_pref) + "</strong>\n"; >+ var error_message = form.sysprefs[modified_pref].message; >+ error_message = error_message.replace(/\s+at .* line \d+\.\s+$/, ''); >+ msg += error_message; >+ } else { >+ msg += "<strong>"+ form.type + "</strong>\n"; >+ } >+ } else { >+ msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n"; >+ } >+ }); >+ humanMsg.displayAlert(msg); >+ >+ KOHA.Preferences.Modified = true; > } > }; > >diff --git a/svc/config/systempreferences b/svc/config/systempreferences >index c54e7499c4..281ca4338b 100755 >--- a/svc/config/systempreferences >+++ b/svc/config/systempreferences >@@ -24,6 +24,13 @@ use C4::Context; > use C4::Service; > use C4::Log; > >+use Koha::Logger; >+ >+use Scalar::Util qw( blessed ); >+use Try::Tiny; >+ >+our $logger = Koha::Logger->get({ interface => 'intranet' }); >+ > =head1 NAME > > svc/config/systempreferences - Web service for setting system preferences >@@ -95,6 +102,7 @@ pref_virtualshelves=0 > =cut > > sub set_preferences { >+ my $errors; > unless ( C4::Context->config( 'demo' ) ) { > foreach my $param ( $query->param() ) { > my ( $pref ) = ( $param =~ /pref_(.*)/ ); >@@ -102,12 +110,29 @@ sub set_preferences { > next if ( !defined( $pref ) ); > > my $value = join( ',', $query->multi_param( $param ) ); >- >- C4::Context->set_preference( $pref, $value ); >+ try { >+ C4::Context->set_preference( $pref, $value ); >+ } catch { >+ $logger->error( "Error saving system preference $pref (" . >+ ref($_) . ')' ); >+ unless (blessed $_ && $_->can('rethrow')) { >+ $errors->{$pref} = { error => ref($_) }; >+ } >+ if ($_->isa('Koha::Exceptions::Config::InvalidSyntax')) { >+ $errors->{$pref} = { error => ref($_), message => $_->error }; >+ } >+ else { >+ $errors->{$pref} = { error => ref($_) }; >+ } >+ }; > } > } > >- C4::Service->return_success( $response ); >+ if ($errors) { >+ return C4::Service->return_error( 'input', undef, sysprefs => $errors ); >+ } >+ >+ C4::Service->return_success( $response ) > } > > C4::Service->dispatch( >-- >2.11.0
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 20930
:
76382
|
76383
|
76384
|
91861
|
91862
|
91863
|
94412
|
94413
|
96108
|
96109
|
96110
|
96111
|
96112
|
96817
|
96818
| 96819 |
96820
|
96821