Bug 30663 - POST /api/v1/suggestions won't honor suggestions limits
Summary: POST /api/v1/suggestions won't honor suggestions limits
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: master
Hardware: All All
: P5 - low major (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-02 20:29 UTC by Lucas Gass
Modified: 2023-06-08 22:26 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00,21.11.06,21.05.16


Attachments
Bug 30663: Add Koha::Suggestions helper methods (4.92 KB, patch)
2022-05-03 14:29 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 30663: Add x-koha-override options to /suggestions (4.19 KB, patch)
2022-05-03 14:29 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 30663: Implement overrides handling in POST /suggestions (3.25 KB, patch)
2022-05-03 14:30 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 30663: Add Koha::Suggestions helper methods (4.98 KB, patch)
2022-05-03 14:37 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 30663: Add x-koha-override options to /suggestions (4.24 KB, patch)
2022-05-03 14:37 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 30663: Implement overrides handling in POST /suggestions (3.31 KB, patch)
2022-05-03 14:37 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 30663: Add Koha::Suggestions helper methods (5.04 KB, patch)
2022-05-04 12:10 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 30663: Add x-koha-override options to /suggestions (4.30 KB, patch)
2022-05-04 12:10 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 30663: Implement overrides handling in POST /suggestions (3.37 KB, patch)
2022-05-04 12:10 UTC, Martin Renvoize
Details | Diff | Splinter Review
[21.11.x] Bug 30663: Add x-koha-override options to /suggestions (3.89 KB, patch)
2022-05-13 18:58 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
[21.11.x] Bug 30663: Implement overrides handling in POST /suggestions (3.38 KB, patch)
2022-05-13 18:58 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass 2022-05-02 20:29:08 UTC
To recreate:

-Set MaxOpenSuggestions to something low, like 1.
-Make some suggestions via the API, making sure they are not anonymous and they include a status of 'ASKED'.
-You can make as many requests as you want, regardless of MaxOpenSuggestions.

I am using this simple jQuery snippet to test:

$.ajax({
    type: 'POST',
    url: '/api/v1/suggestions/',
    data: '{"collection_title": "dasdas", "suggested_by": 5}',
    success: function(data) { console.log('suggestion added'); },
    contentType: "application/json",
    dataType: 'json'
});
Comment 1 Tomás Cohen Arazi 2022-05-03 14:29:50 UTC
Created attachment 134541 [details] [review]
Bug 30663: Add Koha::Suggestions helper methods

This patch adds the following helper methods:

* filter_by_pending
* filter_by_suggested_days_range

This methods follow basically what's done in opac-suggestions.pl
I chose 'pending' as opposed to 'open' to follow what we use in the UI
which might be the case because of being more accurate for end users.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Suggestions.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 2 Tomás Cohen Arazi 2022-05-03 14:29:55 UTC
Created attachment 134542 [details] [review]
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>
Comment 3 Tomás Cohen Arazi 2022-05-03 14:30:00 UTC
Created attachment 134543 [details] [review]
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>
Comment 4 Lucas Gass 2022-05-03 14:37:26 UTC
Created attachment 134544 [details] [review]
Bug 30663: Add Koha::Suggestions helper methods

This patch adds the following helper methods:

* filter_by_pending
* filter_by_suggested_days_range

This methods follow basically what's done in opac-suggestions.pl
I chose 'pending' as opposed to 'open' to follow what we use in the UI
which might be the case because of being more accurate for end users.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Suggestions.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 5 Lucas Gass 2022-05-03 14:37:30 UTC
Created attachment 134545 [details] [review]
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>
Comment 6 Lucas Gass 2022-05-03 14:37:34 UTC
Created attachment 134546 [details] [review]
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>
Comment 7 Martin Renvoize 2022-05-04 12:10:10 UTC
Created attachment 134604 [details] [review]
Bug 30663: Add Koha::Suggestions helper methods

This patch adds the following helper methods:

* filter_by_pending
* filter_by_suggested_days_range

This methods follow basically what's done in opac-suggestions.pl
I chose 'pending' as opposed to 'open' to follow what we use in the UI
which might be the case because of being more accurate for end users.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Suggestions.t
=> SUCCESS: Tests pass!
3. 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>
Comment 8 Martin Renvoize 2022-05-04 12:10:14 UTC
Created attachment 134605 [details] [review]
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>
Comment 9 Martin Renvoize 2022-05-04 12:10:18 UTC
Created attachment 134606 [details] [review]
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>
Comment 10 Martin Renvoize 2022-05-04 12:11:33 UTC
Great work.. as a follow-up bug I'd love to see us move these checks and override into the Object classes.. but given this is a bug and there's already work underway in those classes I think this is an acceptable middle ground.

Passing QA
Comment 11 Tomás Cohen Arazi 2022-05-05 13:33:27 UTC
Pushed for 22.05. Thanks everyone.
Comment 12 Lucas Gass 2022-05-09 19:40:25 UTC
It would be very helpful if this could be backported to 21.11, thanks!
Comment 13 Kyle M Hall 2022-05-13 17:40:54 UTC
Doesn't apply to 21.11.x, please rebase if needed!
Comment 14 Tomás Cohen Arazi 2022-05-13 18:58:32 UTC
Created attachment 134987 [details] [review]
[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>
Comment 15 Tomás Cohen Arazi 2022-05-13 18:58:37 UTC
Created attachment 134988 [details] [review]
[21.11.x] 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>
Comment 16 Kyle M Hall 2022-05-13 19:17:21 UTC
Pushed to 21.11.x for 21.11.06
Comment 17 Victor Grousset/tuxayo 2022-06-25 02:52:22 UTC
Backported: Pushed to 21.05.x branch for 21.05.16