From 5fccea5984333464e9f1ad8d37d556fdc7ab08cd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Feb 2023 15:07:46 +0100 Subject: [PATCH] Bug 32923: Fix x-koha-embed from EHoldings/*/* We were validating twice the input and it broke the x-koha-embed header. I don't really know what's happening, but here is how to recreate the problem: 1. Edit Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm 2. Add the following lines in Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm, in the list method warn $c->req->headers->header('x-koha-embed'); 3. curl -v -s -u koha:koha --request GET http://kohadev-intra.mydnsname.org:8081/api/v1/erm/eholdings/ebsco/packages --header "x-koha-embed: resources+count,vendor" => There is no vendor in the response => The warn displays "resources+count" If you apply this patch you will notice that "vendor" is part of the response and the warn displays "resources+count, vendor" --- Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm | 6 +++--- Koha/REST/V1/ERM/EHoldings/Packages/Local.pm | 10 +++++----- Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm | 6 +++--- Koha/REST/V1/ERM/EHoldings/Resources/Local.pm | 4 ++-- Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm | 4 ++-- Koha/REST/V1/ERM/EHoldings/Titles/Local.pm | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm index 6c4e7c4ade5..defd5ea0a7c 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm @@ -26,7 +26,7 @@ use Scalar::Util qw( blessed ); use Try::Tiny qw( catch try ); sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { @@ -87,7 +87,7 @@ sub list { } sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my ( $vendor_id, $package_id ) = split '-', @@ -119,7 +119,7 @@ sub get { } sub edit { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $body = $c->validation->param('body'); diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm b/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm index f9dfa7022cb..538766d6400 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm @@ -33,7 +33,7 @@ use Try::Tiny qw( catch try ); =cut sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $packages_set = Koha::ERM::EHoldings::Packages->search( { 'me.external_id' => undef } ); @@ -50,7 +50,7 @@ sub list { =cut sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $package_id = $c->validation->param('package_id'); @@ -81,7 +81,7 @@ Controller function that handles adding a new Koha::ERM::EHoldings::Package obje =cut sub add { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { Koha::Database->new->schema->txn_do( @@ -147,7 +147,7 @@ Controller function that handles updating a Koha::ERM::EHoldings::Package object =cut sub update { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; my $package_id = $c->validation->param('package_id'); my $package = Koha::ERM::EHoldings::Packages->find( $package_id ); @@ -217,7 +217,7 @@ sub update { =cut sub delete { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; my $package = Koha::ERM::EHoldings::Packages->find( $c->validation->param('package_id') ); unless ($package) { diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm index 5f945872807..abd4433ac8e 100644 --- a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm @@ -34,7 +34,7 @@ use Try::Tiny; =cut sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { @@ -121,7 +121,7 @@ sub list { =cut sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my ( $vendor_id, $package_id, $resource_id ) = split '-', @@ -177,7 +177,7 @@ sub get { =cut sub edit { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $body = $c->validation->param('body'); diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm b/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm index 81b4a383c60..e4fa55aeb75 100644 --- a/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm @@ -33,7 +33,7 @@ use Try::Tiny qw( catch try ); =cut sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $package_id = $c->validation->param('package_id'); @@ -57,7 +57,7 @@ Controller function that handles retrieving a single Koha::ERM::EHoldings::Resou =cut sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $resource_id = $c->validation->param('resource_id'); diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm index cc2f4142b2d..cf3c788cdae 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm @@ -34,7 +34,7 @@ use Try::Tiny qw( catch try ); =cut sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { @@ -114,7 +114,7 @@ sub list { =cut sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $title_id = $c->validation->param('title_id'); diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm index 51944630348..28444f5cc52 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm @@ -34,7 +34,7 @@ use Try::Tiny qw( catch try ); =cut sub list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $titles_set = Koha::ERM::EHoldings::Titles->new; @@ -54,7 +54,7 @@ Controller function that handles retrieving a single Koha::ERM::EHoldings::Title =cut sub get { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { my $title_id = $c->validation->param('title_id'); @@ -84,7 +84,7 @@ Controller function that handles adding a new Koha::ERM::EHoldings::Title object =cut sub add { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; return try { Koha::Database->new->schema->txn_do( @@ -150,7 +150,7 @@ Controller function that handles updating a Koha::ERM::EHoldings::Title object =cut sub update { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; my $title_id = $c->validation->param('title_id'); my $title = Koha::ERM::EHoldings::Titles->find( $title_id ); @@ -217,7 +217,7 @@ sub update { =cut sub delete { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; my $title = Koha::ERM::EHoldings::Titles->find( $c->validation->param('title_id') ); unless ($title) { @@ -244,7 +244,7 @@ sub delete { =cut sub import_from_list { - my $c = shift->openapi->valid_input or return; + my $c = shift or return; my $body = $c->validation->param('body'); my $list_id = $body->{list_id}; -- 2.25.1