Bugzilla – Attachment 117326 Details for
Bug 27760
Add handling for x-koha-override
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27760: Add stash_overrides helper
Bug-27760-Add-stashoverrides-helper.patch (text/plain), 2.93 KB, created by
David Nind
on 2021-02-25 14:12:17 UTC
(
hide
)
Description:
Bug 27760: Add stash_overrides helper
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-02-25 14:12:17 UTC
Size:
2.93 KB
patch
obsolete
>From 3ac57514e1688fa3845746d17c9b32fea2ea27f7 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 25 Feb 2021 09:35:28 -0300 >Subject: [PATCH] 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> >--- > Koha/REST/Plugin/Query.pm | 28 ++++++++++++++++++++++++++++ > t/Koha/REST/Plugin/Query.t | 27 ++++++++++++++++++++++++++- > 2 files changed, 54 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index ea6695ff37..32dc9b173c 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -240,6 +240,34 @@ Merges parameters from $q_params into $filtered_params. > 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; >+ } >+ ); > } > > =head2 Internal methods >diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t >index b504f3ba5f..9a5ddbe346 100755 >--- a/t/Koha/REST/Plugin/Query.t >+++ b/t/Koha/REST/Plugin/Query.t >@@ -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 { >@@ -485,3 +497,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 >+}; >-- >2.11.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 27760
:
117308
|
117309
|
117326
|
117327
|
117342
|
117343
|
117344
|
118108
|
118110
|
120112
|
120113
|
120114
|
120115