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> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
9b2226a649
commit
7647d51478
2 changed files with 41 additions and 2 deletions
|
@ -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 });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue