Bug 35053

Summary: Item-level rules not checked if both item_id and biblio_id are passed
Product: Koha Reporter: Nick Clemens (kidclamp) <nick>
Component: REST APIAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P5 - low CC: emily.lamancusa, fridolin.somers, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=32702
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.05,22.11.12
Circulation function:
Attachments: Bug 35053: Regression tests
Bug 35053: Make sure request is checked as an item-level request if item_id passed
Bug 35053: Regression tests
Bug 35053: Make sure request is checked as an item-level request if item_id passed
Bug 35053: Regression tests
Bug 35053: Make sure request is checked as an item-level request if item_id passed

Description Nick Clemens (kidclamp) 2023-10-13 19:30:01 UTC
In the checks we have:

if ( $item_id and $biblio_id ) {
....
   $biblio = Koha::Biblios->find($biblio_id);
...
}

$item does not get assigned, then later:

            my $can_place_hold
                = $item
                ? C4::Reserves::CanItemBeReserved( $patron, $item )
                : C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id );

So while the item may not be holdable, we check if the bib is, then place the hold using the item_id
Comment 1 Tomás Cohen Arazi (tcohen) 2023-10-17 12:12:02 UTC
Created attachment 157231 [details] [review]
Bug 35053: Regression tests
Comment 2 Tomás Cohen Arazi (tcohen) 2023-10-17 12:12:05 UTC
Created attachment 157232 [details] [review]
Bug 35053: Make sure request is checked as an item-level request if item_id passed

This patch makes the validation code have the `$item` variable defined
when checking holdability, in the case both `item_id` and `biblio_id`
params are passed.

Otherwise, if the requested item is not holdable, but a biblio-level
hold *could* be placed, the item-level hold is placed.

This is highlighted by the regression tests.

To test:
1. Apply the regression tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/holds.t
=> FAIL: Tests don't pass. A request that should be rejected is allowed
because biblio-level hold is allowed.
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass! Item-level rules are checked and thus the
request rejected (code 403)
5. Sign off :-D
Comment 3 David Nind 2023-10-19 07:26:30 UTC
Created attachment 157389 [details] [review]
Bug 35053: Regression tests

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2023-10-19 07:26:32 UTC
Created attachment 157390 [details] [review]
Bug 35053: Make sure request is checked as an item-level request if item_id passed

This patch makes the validation code have the `$item` variable defined
when checking holdability, in the case both `item_id` and `biblio_id`
params are passed.

Otherwise, if the requested item is not holdable, but a biblio-level
hold *could* be placed, the item-level hold is placed.

This is highlighted by the regression tests.

To test:
1. Apply the regression tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/holds.t
=> FAIL: Tests don't pass. A request that should be rejected is allowed
because biblio-level hold is allowed.
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass! Item-level rules are checked and thus the
request rejected (code 403)
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Nick Clemens (kidclamp) 2023-10-19 11:57:25 UTC
Created attachment 157424 [details] [review]
Bug 35053: Regression tests

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 6 Nick Clemens (kidclamp) 2023-10-19 11:57:27 UTC
Created attachment 157425 [details] [review]
Bug 35053: Make sure request is checked as an item-level request if item_id passed

This patch makes the validation code have the `$item` variable defined
when checking holdability, in the case both `item_id` and `biblio_id`
params are passed.

Otherwise, if the requested item is not holdable, but a biblio-level
hold *could* be placed, the item-level hold is placed.

This is highlighted by the regression tests.

To test:
1. Apply the regression tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/holds.t
=> FAIL: Tests don't pass. A request that should be rejected is allowed
because biblio-level hold is allowed.
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass! Item-level rules are checked and thus the
request rejected (code 403)
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 7 Tomás Cohen Arazi (tcohen) 2023-10-20 14:04:03 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 8 Fridolin Somers 2023-10-25 21:48:11 UTC
Pushed to 23.05.x for 23.05.05
Comment 9 Matt Blenkinsop 2023-11-13 14:03:33 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x
Comment 10 Emily Lamancusa (emlam) 2023-11-28 15:16:16 UTC
*** Bug 33477 has been marked as a duplicate of this bug. ***