Bug 27760: Add stash_overrides helper
This patch adds a simple helper that reads the x-koha-override request header, and processes it to stash a hashref with the passed overrides. No check on the overrides themselves is done, as they should be validated using the OpenAPI spec. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/auth_authenticate_api_request.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: David Nind <david@davidnind.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
8fe090ffe3
commit
c2cc6b401a
2 changed files with 54 additions and 1 deletions
|
@ -262,6 +262,34 @@ Merges parameters from $q_params into $filtered_params.
|
|||
if $THE_embed;
|
||||
}
|
||||
|
||||
return $c;
|
||||
}
|
||||
);
|
||||
|
||||
=head3 stash_overrides
|
||||
|
||||
$c->stash_overrides();
|
||||
|
||||
=cut
|
||||
|
||||
$app->helper(
|
||||
'stash_overrides' => sub {
|
||||
|
||||
my ( $c ) = @_;
|
||||
|
||||
my $override_header = $c->req->headers->header('x-koha-override');
|
||||
|
||||
my $overrides = {};
|
||||
|
||||
if ( $override_header ) {
|
||||
my @overrides = ();
|
||||
foreach my $override ( split /\s*,\s*/, $override_header ) {
|
||||
$overrides->{$override} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$c->stash( 'koha.overrides' => $overrides );
|
||||
|
||||
return $c;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -255,6 +255,18 @@ get '/stash_embed_no_spec' => sub {
|
|||
};
|
||||
};
|
||||
|
||||
get '/stash_overrides' => sub {
|
||||
my $c = shift;
|
||||
|
||||
$c->stash_overrides();
|
||||
my $overrides = $c->stash('koha.overrides');
|
||||
|
||||
$c->render(
|
||||
status => 200,
|
||||
json => $overrides
|
||||
);
|
||||
};
|
||||
|
||||
sub to_model {
|
||||
my ($args) = @_;
|
||||
$args->{three} = delete $args->{tres}
|
||||
|
@ -264,7 +276,7 @@ sub to_model {
|
|||
|
||||
# The tests
|
||||
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 7;
|
||||
use Test::Mojo;
|
||||
|
||||
subtest 'extract_reserved_params() tests' => sub {
|
||||
|
@ -487,3 +499,16 @@ subtest 'stash_embed() tests' => sub {
|
|||
);
|
||||
|
||||
};
|
||||
|
||||
subtest 'stash_overrides() tests' => sub {
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok( '/stash_overrides' => { 'x-koha-override' => 'any,none,some_other,any,' } )
|
||||
->json_is( { 'any' => 1, 'none' => 1, 'some_other' => 1 } ); # empty string and duplicates are skipped
|
||||
|
||||
$t->get_ok( '/stash_overrides' => { 'x-koha-override' => '' } )
|
||||
->json_is( {} ); # empty string is skipped
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue