Bugzilla – Attachment 134606 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]
Bug 30663: Implement overrides handling in POST /suggestions
Bug-30663-Implement-overrides-handling-in-POST-sug.patch (text/plain), 3.37 KB, created by
Martin Renvoize (ashimema)
on 2022-05-04 12:10:18 UTC
(
hide
)
Description:
Bug 30663: Implement overrides handling in POST /suggestions
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-05-04 12:10:18 UTC
Size:
3.37 KB
patch
obsolete
>From de1abd71ba64ed41b2303df2697693c0bc26ad52 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 3 May 2022 11:23:23 -0300 >Subject: [PATCH] Bug 30663: Implement overrides handling in POST /suggestions > >This patch implements the override checks in the controller as expected >by the previous patch. > >To test: >1. Apply this bug patches up to 'Add x-koha-override options...' >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/suggestions.t >=> FAIL: Tests fail! The controller doesn't care about overrides or > sysprefs about suggestions limits. >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Things work! >5. Sign off :-D > >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> >--- > Koha/REST/V1/Suggestions.pm | 49 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > >diff --git a/Koha/REST/V1/Suggestions.pm b/Koha/REST/V1/Suggestions.pm >index 404318da88..d7a63f2c4e 100644 >--- a/Koha/REST/V1/Suggestions.pm >+++ b/Koha/REST/V1/Suggestions.pm >@@ -98,6 +98,55 @@ sub add { > $body->{'status'} = 'ASKED' > unless defined $body->{'status'}; > >+ my $overrides = $c->stash('koha.overrides'); >+ >+ unless ( $overrides->{any} ) { >+ >+ unless ( $overrides->{max_total} ) { >+ >+ if ( C4::Context->preference('MaxTotalSuggestions') ne '' >+ && C4::Context->preference('NumberOfSuggestionDays') ne '' ) >+ { >+ my $max_total = C4::Context->preference('MaxTotalSuggestions'); >+ my $days_range = C4::Context->preference('NumberOfSuggestionDays'); >+ >+ if ( $max_total and $days_range ) { >+ >+ my $total = Koha::Suggestions->search({ suggestedby => $body->{suggested_by} }) >+ ->filter_by_suggested_days_range( $days_range ) >+ ->count; >+ >+ if ( $total >= $max_total ) { >+ return $c->render( >+ status => 400, >+ openapi => { >+ error => "Reached the maximum suggestions limit", >+ error_code => 'max_total_reached' >+ } >+ ); >+ } >+ } >+ } >+ } >+ >+ unless ( $overrides->{max_pending} ) { >+ if ( C4::Context->preference('MaxOpenSuggestions') ne '' ) { >+ my $total_pending = Koha::Suggestions->search({ suggestedby => $body->{suggested_by} }) >+ ->filter_by_pending >+ ->count; >+ if ( $total_pending >= C4::Context->preference('MaxOpenSuggestions') ) { >+ return $c->render( >+ status => 400, >+ openapi => { >+ error => "Reached the maximum pending suggestions limit", >+ error_code => 'max_pending_reached' >+ } >+ ); >+ } >+ } >+ } >+ } >+ > return try { > my $suggestion = Koha::Suggestion->new_from_api( $body )->store; > $suggestion->discard_changes; >-- >2.20.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