Bugzilla – Attachment 134987 Details for
Bug 30663
POST /api/v1/suggestions won't honor suggestions limits
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[21.11.x] Bug 30663: Add x-koha-override options to /suggestions
2111x-Bug-30663-Add-x-koha-override-options-to-sug.patch (text/plain), 3.89 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-05-13 18:58:32 UTC
(
hide
)
Description:
[21.11.x] Bug 30663: Add x-koha-override options to /suggestions
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-05-13 18:58:32 UTC
Size:
3.89 KB
patch
obsolete
>From 1a5d559e44cb1617db35fae53f789ca9ca486dba Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 3 May 2022 11:20:46 -0300 >Subject: [PATCH] [21.11.x] Bug 30663: Add x-koha-override options to > /suggestions > >This patch adds the x-koha-override header parameter to the route that >is used to create suggestions, POST /suggestions. > >The idea is that adding suggestions will be rejected under certain >conditions unless x-koha-override is passed with appropriate values. The >added overrides are: > >* any >* max_total >* max_pending > >Tests are added for the expected behavior. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > api/v1/swagger/paths/suggestions.yaml | 10 ++++++ > t/db_dependent/api/v1/suggestions.t | 46 ++++++++++++++++++++++++++- > 2 files changed, 55 insertions(+), 1 deletion(-) > >diff --git a/api/v1/swagger/paths/suggestions.yaml b/api/v1/swagger/paths/suggestions.yaml >index e14ddb78ab..b1a8a9e258 100644 >--- a/api/v1/swagger/paths/suggestions.yaml >+++ b/api/v1/swagger/paths/suggestions.yaml >@@ -53,6 +53,16 @@ > required: true > schema: > $ref: ../definitions.yaml#/suggestion >+ - name: x-koha-override >+ in: header >+ required: false >+ description: | >+ Overrides list sent as a request header >+ Valid values: >+ * any >+ * max_total >+ * max_pending >+ type: string > produces: > - application/json > responses: >diff --git a/t/db_dependent/api/v1/suggestions.t b/t/db_dependent/api/v1/suggestions.t >index 6ec1010003..9ad51e27bc 100755 >--- a/t/db_dependent/api/v1/suggestions.t >+++ b/t/db_dependent/api/v1/suggestions.t >@@ -149,7 +149,7 @@ subtest 'get() tests' => sub { > > subtest 'add() tests' => sub { > >- plan tests => 15; >+ plan tests => 16; > > $schema->storage->txn_begin; > >@@ -237,6 +237,50 @@ subtest 'add() tests' => sub { > ] > ); > >+ subtest 'x-koha-override tests' => sub { >+ >+ plan tests => 14; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ t::lib::Mocks::mock_preference( 'MaxTotalSuggestions', 4 ); >+ t::lib::Mocks::mock_preference( 'MaxOpenSuggestions', 2 ); >+ t::lib::Mocks::mock_preference( 'NumberOfSuggestionDays', 2 ); >+ >+ my $suggestion = $builder->build_object( >+ { class => 'Koha::Suggestions', >+ value => { suggestedby => $patron->id, STATUS => 'ACCEPTED' } >+ } >+ ); >+ >+ my $suggestion_data = $suggestion->to_api; >+ delete $suggestion_data->{suggestion_id}; >+ delete $suggestion_data->{status}; >+ >+ $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is( 201, 'First pending suggestion' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is( 201, 'Second pending suggestion' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is(400) >+ ->json_is( '/error_code' => 'max_pending_reached' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/suggestions" >+ => { 'x-koha-override' => 'max_pending' } >+ => json => $suggestion_data ) >+ ->status_is( 201, 'max_pending override does the job' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is(400) >+ ->json_is( '/error_code' => 'max_total_reached' ); >+ >+ $t->post_ok( >+ "//$userid:$password@/api/v1/suggestions" => { 'x-koha-override' => 'any' } => json => $suggestion_data ) >+ ->status_is( 201, 'any overrides anything' ); >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >2.34.1
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 30663
:
134541
|
134542
|
134543
|
134544
|
134545
|
134546
|
134604
|
134605
|
134606
| 134987 |
134988