From bc5da8a6ea996eef36bcfef2025caf36c228975e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 23 Oct 2017 12:07:04 +0200 Subject: [PATCH] Bug 10306: (QA follow-up) More feedback for admins in koha2marclinks As requested by Tomas, this patch does: [1] Add a js alert when you did not type field,subfield [2] Print a yellow alert div when the field,subfield is not found. [3] Bonus: Make it little bit more secure by demanding a POST. (Leaving CSRF etc. for another report.) Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- admin/koha2marclinks.pl | 11 ++++++++--- .../intranet-tmpl/prog/en/modules/admin/koha2marclinks.tt | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/admin/koha2marclinks.pl b/admin/koha2marclinks.pl index d6f2b5f..b337a3c 100755 --- a/admin/koha2marclinks.pl +++ b/admin/koha2marclinks.pl @@ -48,12 +48,17 @@ my $cache = Koha::Caches->get_instance(); # Update data before showing the form my $no_upd; -if( $input->param('add_field') ) { +if( $input->param('add_field') && $input->request_method eq 'POST' ) { # add a mapping to all frameworks my ($kohafield, $tag, $sub) = split /,/, $input->param('add_field'), 3; - Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => $kohafield }); + my $rs = Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub }); + if( $rs->count ) { + $rs->update({ kohafield => $kohafield }); + } else { + $template->param( error_add => 1, error_info => "$tag, $sub" ); + } -} elsif( $input->param('remove_field') ) { +} elsif( $input->param('remove_field') && $input->request_method eq 'POST' ) { # remove a mapping from all frameworks my ($tag, $sub) = split /,/, $input->param('remove_field'), 2; Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => undef }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/koha2marclinks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/koha2marclinks.tt index 32061a0..afddb9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/koha2marclinks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/koha2marclinks.tt @@ -13,6 +13,8 @@ function AddFld(kohafield) { if( temp.length == 2 ) { $('#add_field').val( kohafield+','+fieldstr ); $('#koha2marc').submit(); + } else { + alert( "Invalid input. Enter something like: 245,a" ); } } @@ -42,6 +44,10 @@ function RemFld(tagfield, subfield ) {
+[% IF error_add %] +
Failed to add mapping for [% error_info %]
+[% END %] + -- 2.10.2
Koha field