Bug 37256: Defined 'context' of circulation rules

This is a follow-up to the previous bug exposing circulation rules over
the API.

We formally define a definition for a circulation rules set including a
new 'context' object the defines the context, library_id,
patron_category_id and item_type_id combination of the rules returned.

This is just a patch I missed in the last submission that I'd meant to
add and it's important for the PUT part of this patchset.

Sponsored-by: Glasgow Colleges Library Group <https://library.cityofglasgowcollege.ac.uk>
Signed-off-by: George Harkins <George.Harkins@cityofglasgowcollege.ac.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-08-02 14:19:18 +01:00 committed by Katrin Fischer
parent 85d9861fb3
commit f4342c922d
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
5 changed files with 53 additions and 12 deletions

View File

@ -151,12 +151,25 @@ sub list_rules {
{
select => $select,
as => $as,
group_by => [ 'branchcode', 'categorycode', 'itemtype' ]
group_by => [ 'branchcode', 'categorycode', 'itemtype' ],
order_by => [ 'branchcode', 'categorycode', 'itemtype' ],
}
)->unblessed;
}
# Map context into rules
@{$rules} = map {
my %new_rule = %$_;
my %context = (
"library_id" => delete $new_rule{"branchcode"} // "*",
"patron_category_id" => delete $new_rule{"categorycode"} // "*",
"item_type_id" => delete $new_rule{"itemtype"} // "*",
);
$new_rule{"context"} = \%context;
\%new_rule;
} @{$rules};
return $c->render(
status => 200,
openapi => $rules

View File

@ -0,0 +1,19 @@
---
type: object
properties:
context:
type: object
properties:
patron_category_id:
type: string
description: Patron category id
library_id:
type: string
description: Library branch id
item_type_id:
type: string
description: Item type id
description: Context of the ruleset
additionalProperties: true
required:
- context

View File

@ -40,7 +40,7 @@
schema:
type: array
items:
type: object
$ref: "../swagger.yaml#/definitions/circulation_rules"
"400":
description: Bad request
schema:
@ -104,4 +104,4 @@
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
- circulate: circulate_remaining_permissions
- circulate: circulate_remaining_permissions

View File

@ -12,6 +12,8 @@ definitions:
$ref: ./definitions/authorised_value.yaml
authorised_value_category:
$ref: ./definitions/authorised_value_category.yaml
circulation_rules:
$ref: ./definitions/circulation_rules.yaml
identity_provider:
$ref: ./definitions/identity_provider.yaml
identity_provider_domain:
@ -1289,4 +1291,4 @@ tags:
x-displayName: Two factor authentication
- description: "Manage vendors for the acquisitions module\n"
name: vendors
x-displayName: Vendors
x-displayName: Vendors

View File

@ -143,8 +143,12 @@ subtest 'list_rules() tests' => sub {
->json_is( '/0/finedays' => 5, "Default finedays rule returned when no library is added to request query" );
# Limit to only rules we're interested in
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules=fine,finedays")->status_is(200)
->json_is( '/0' => { fine => 2, finedays => 5 }, "Only the two rules we asked for are returned" );
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules=fine,finedays")->status_is(200)->json_is(
'/0' => {
context => { item_type_id => '*', patron_category_id => '*', library_id => '*' }, fine => 2, finedays => 5
},
"Only the two rules we asked for are returned"
);
# Warn on unsupported query parameter
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")->status_is(400)
@ -236,9 +240,9 @@ subtest 'list_rules() tests' => sub {
# First rule set should march default, default, default
if ( $index == 0 ) {
ok( $pointer->get('/branchcode') eq "*"
&& $pointer->get('/itemtype') eq '*'
&& $pointer->get('/categorycode') eq '*', "Default rules returned first" );
ok( $pointer->get('/context/library_id') eq "*"
&& $pointer->get('/context/item_type_id') eq '*'
&& $pointer->get('/context/patron_category_id') eq '*', "Default rules returned first" );
}
# Iterate over the list of expected keys for each hash
@ -265,9 +269,12 @@ subtest 'list_rules() tests' => sub {
# First (and only) rule set should match branchcode, default, default.
if ( $index == 0 ) {
ok( $pointer->get('/branchcode') eq $branchcode
&& $pointer->get('/itemtype') eq '*'
&& $pointer->get('/categorycode') eq '*', "Branchcode rule set returned when filtered" );
ok(
$pointer->get('/context/library_id') eq $branchcode
&& $pointer->get('/context/item_type_id') eq '*'
&& $pointer->get('/context/patron_category_id') eq '*',
"Branchcode rule set returned when filtered"
);
}
# Iterate over the list of expected keys for each hash