From 15a5881cdcc0629f9f415071fcd22e6c03cfe9a1 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 6 Nov 2020 14:50:29 -0300 Subject: [PATCH] Bug 23019: (follow-up) Fix other things This patch: * Fixes table name change * Adds schema file * Changes api parameter name * Fixes string escaping * Fixes error handling --- Koha/ImportBatchProfile.pm | 2 +- Koha/ImportBatchProfiles.pm | 2 +- Koha/REST/V1/ImportBatchProfiles.pm | 4 +-- Koha/Schema/Result/ImportBatch.pm | 8 ++--- ...atchesProfile.pm => ImportBatchProfile.pm} | 29 +++++++++++++++---- api/v1/swagger/parameters.json | 4 +-- .../parameters/import_batch_profile.json | 4 +-- .../swagger/paths/import_batch_profiles.json | 2 +- .../en/modules/tools/stage-marc-import.tt | 6 ++-- 9 files changed, 39 insertions(+), 22 deletions(-) rename Koha/Schema/Result/{ImportBatchesProfile.pm => ImportBatchProfile.pm} (81%) diff --git a/Koha/ImportBatchProfile.pm b/Koha/ImportBatchProfile.pm index c0137f8265..1b349fc6b9 100644 --- a/Koha/ImportBatchProfile.pm +++ b/Koha/ImportBatchProfile.pm @@ -48,7 +48,7 @@ sub to_api_mapping { =cut sub _type { - return 'ImportBatchesProfile'; + return 'ImportBatchProfile'; } 1; \ No newline at end of file diff --git a/Koha/ImportBatchProfiles.pm b/Koha/ImportBatchProfiles.pm index 46800f1c59..7787af8845 100644 --- a/Koha/ImportBatchProfiles.pm +++ b/Koha/ImportBatchProfiles.pm @@ -37,7 +37,7 @@ Koha::ImportBatchProfiles - Koha ImportBatchProfiles Object class =cut sub _type { - return 'ImportBatchesProfile'; + return 'ImportBatchProfile'; } =head3 object_class diff --git a/Koha/REST/V1/ImportBatchProfiles.pm b/Koha/REST/V1/ImportBatchProfiles.pm index 1533ef8a60..9988d0f002 100644 --- a/Koha/REST/V1/ImportBatchProfiles.pm +++ b/Koha/REST/V1/ImportBatchProfiles.pm @@ -91,7 +91,7 @@ sub edit { my $c = shift->openapi->valid_input or return; return try { - my $profile_id = $c->validation->param('profile_id'); + my $profile_id = $c->validation->param('import_batch_profile_id'); my $profile = Koha::ImportBatchProfiles->find( $profile_id ); unless ($profile) { return $c->render( status => 404, @@ -121,7 +121,7 @@ Method that handles deleting a Koha::ImportBatchProfile object sub delete { my $c = shift->openapi->valid_input or return; - my $profile_id = $c->validation->param('profile_id'); + my $profile_id = $c->validation->param('import_batch_profile_id'); my $profile = Koha::ImportBatchProfiles->find( $profile_id ); unless ($profile) { diff --git a/Koha/Schema/Result/ImportBatch.pm b/Koha/Schema/Result/ImportBatch.pm index 63641181dd..829297596c 100644 --- a/Koha/Schema/Result/ImportBatch.pm +++ b/Koha/Schema/Result/ImportBatch.pm @@ -246,13 +246,13 @@ __PACKAGE__->has_many( Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( "profile", - "Koha::Schema::Result::ImportBatchesProfile", + "Koha::Schema::Result::ImportBatchProfile", { id => "profile_id" }, { is_deferrable => 1, @@ -263,8 +263,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-06-03 15:47:08 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jGfBdM8ht823HaxSr2c9Wg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-11-06 13:52:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nnGJ0Nvgiz123+ic7v0GqQ =head2 koha_object_class diff --git a/Koha/Schema/Result/ImportBatchesProfile.pm b/Koha/Schema/Result/ImportBatchProfile.pm similarity index 81% rename from Koha/Schema/Result/ImportBatchesProfile.pm rename to Koha/Schema/Result/ImportBatchProfile.pm index a17b0054d4..fb309cde71 100644 --- a/Koha/Schema/Result/ImportBatchesProfile.pm +++ b/Koha/Schema/Result/ImportBatchProfile.pm @@ -1,12 +1,12 @@ use utf8; -package Koha::Schema::Result::ImportBatchesProfile; +package Koha::Schema::Result::ImportBatchProfile; # Created by DBIx::Class::Schema::Loader # DO NOT MODIFY THE FIRST PART OF THIS FILE =head1 NAME -Koha::Schema::Result::ImportBatchesProfile +Koha::Schema::Result::ImportBatchProfile =cut @@ -15,11 +15,11 @@ use warnings; use base 'DBIx::Class::Core'; -=head1 TABLE: C +=head1 TABLE: C =cut -__PACKAGE__->table("import_batches_profile"); +__PACKAGE__->table("import_batch_profiles"); =head1 ACCESSORS @@ -132,6 +132,20 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("u_import_batch_profiles__name", ["name"]); + =head1 RELATIONS =head2 import_batches @@ -150,8 +164,11 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-06-03 15:47:08 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BWFz5yLEEP6ANuAWKAMCeg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-11-06 13:52:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kThbQZTT2c0fuWAGgvoDLQ + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->add_columns( '+parse_items' => { is_boolean => 1 }, diff --git a/api/v1/swagger/parameters.json b/api/v1/swagger/parameters.json index 97a3a5550c..b39ba87cd1 100644 --- a/api/v1/swagger/parameters.json +++ b/api/v1/swagger/parameters.json @@ -11,8 +11,8 @@ "patron_id_qp": { "$ref": "parameters/patron.json#/patron_id_qp" }, - "profile_id_pp": { - "$ref": "parameters/import_batch_profile.json#/profile_id_pp" + "import_batch_profile_id_pp": { + "$ref": "parameters/import_batch_profile.json#/import_batch_profile_id_pp" }, "city_id_pp": { "$ref": "parameters/city.json#/city_id_pp" diff --git a/api/v1/swagger/parameters/import_batch_profile.json b/api/v1/swagger/parameters/import_batch_profile.json index 3a0804045a..7b4a000a1e 100644 --- a/api/v1/swagger/parameters/import_batch_profile.json +++ b/api/v1/swagger/parameters/import_batch_profile.json @@ -1,6 +1,6 @@ { - "profile_id_pp": { - "name": "profile_id", + "import_batch_profile_id_pp": { + "name": "import_batch_profile_id", "in": "path", "description": "Internal profile identifier", "required": true, diff --git a/api/v1/swagger/paths/import_batch_profiles.json b/api/v1/swagger/paths/import_batch_profiles.json index 0e5860c67b..db802f492b 100644 --- a/api/v1/swagger/paths/import_batch_profiles.json +++ b/api/v1/swagger/paths/import_batch_profiles.json @@ -352,7 +352,7 @@ }, "x-koha-authorization": { "permissions": { - "catalogue": "1" + "tools": "stage_marc_import" } } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt index f3f03c47c9..61626ffb63 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt @@ -362,7 +362,7 @@ return getProfiles(profile.profile_id); }) .catch(function(error) { - alert(_("An error occurred")+"\n\n"+error); + alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText)); }) }); @@ -386,7 +386,7 @@ return getProfiles(); }) .catch(function(error) { - alert(_("An error occurred")+"\n\n"+error); + alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText)); }) }); }); @@ -460,7 +460,7 @@ opt.prop('selected', true); } opt.attr("value", profile.profile_id); - opt.html(profile.name); + opt.text(profile.name); opt.data("profile", profile); }); }) -- 2.25.0