Bugzilla – Attachment 125903 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), 2.95 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-07 18:05:00 UTC
(
hide
)
Description:
Bug 28948: Teach objects.search about public requests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-07 18:05:00 UTC
Size:
2.95 KB
patch
obsolete
>From 814a87cc9579cf0646d2e772e3ecf05690029bea 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> >--- > 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 7ccc1c4cf4..ddf2194530 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 e85a57f78d..47a953a834 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.33.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 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