Bugzilla – Attachment 126121 Details for
Bug 28948
Add a /public counterpart for the libraries REST endpoints
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28948: Teach objects.search about public requests
Bug-28948-Teach-objectssearch-about-public-request.patch (text/plain), 3.01 KB, created by
Kyle M Hall (khall)
on 2021-10-12 18:45:33 UTC
(
hide
)
Description:
Bug 28948: Teach objects.search about public requests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2021-10-12 18:45:33 UTC
Size:
3.01 KB
patch
obsolete
>From 599d0557cf902b723fffc008d4133581cb09d77f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 7 Jan 2021 13:18:27 -0300 >Subject: [PATCH] Bug 28948: Teach objects.search about public requests > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/Plugin/Objects.pm | 4 ++- > t/db_dependent/Koha/REST/Plugin/Objects.t | 39 ++++++++++++++++++++++- > 2 files changed, 41 insertions(+), 2 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 7ccc1c4cf49..ddf21945307 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -91,6 +91,8 @@ for API rendering. > > # Extract reserved params > my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args); >+ # Privileged reques? >+ my $is_public = $c->stash('is_public'); > # Look for embeds > my $embed = $c->stash('koha.embed'); > >@@ -162,7 +164,7 @@ for API rendering. > } > ); > >- return $objects->to_api({ embed => $embed }); >+ return $objects->to_api({ embed => $embed, public => $is_public }); > } > ); > } >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index e85a57f78df..47a953a8347 100755 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -79,8 +79,27 @@ get '/biblios' => sub { > $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} ); > }; > >+get '/libraries/:library_id_1/:library_id_2' => sub { >+ >+ my $c = shift; >+ >+ # Emulate a public route by stashing the is_public value >+ $c->stash( 'is_public' => 1 ); >+ >+ my $library_id_1 = $c->param('library_id_1'); >+ my $library_id_2 = $c->param('library_id_2'); >+ >+ my $libraries_rs = Koha::Libraries->search({ branchcode => [ $library_id_1, $library_id_2 ] }); >+ my $libraries = $c->objects->search( $libraries_rs ); >+ >+ $c->render( >+ status => 200, >+ json => $libraries >+ ); >+}; >+ > # The tests >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::Mojo; > > use t::lib::Mocks; >@@ -512,3 +531,21 @@ subtest 'objects.find helper, embed' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'objects.search helper, public requests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $t = Test::Mojo->new; >+ >+ $t->get_ok( '/libraries/'.$library_1->id.'/'.$library_2->id ) >+ ->json_is('/0' => $library_1->to_api({ public => 1 }), 'Public representation of $library_1 is retrieved') >+ ->json_is('/1' => $library_2->to_api({ public => 1 }), 'Public representation of $library_2 is retrieved'); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.30.2
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 28948
:
124479
|
124480
|
124481
|
124482
|
124483
|
124749
|
124911
|
124914
|
125901
|
125902
|
125903
|
125904
|
125905
|
125906
|
125907
|
125908
|
125911
|
125912
|
126111
|
126112
|
126113
|
126114
|
126115
|
126116
|
126117
|
126118
|
126119
|
126120
| 126121 |
126122
|
126123
|
126124
|
126125
|
126126
|
127054
|
127055