View | Details | Raw Unified | Return to bug 37256
Collapse All | Expand All

(-)a/Koha/REST/V1/CirculationRules.pm (-1 / +13 lines)
Lines 50-56 sub list_rules { Link Here
50
    my $c = shift->openapi->valid_input or return;
50
    my $c = shift->openapi->valid_input or return;
51
51
52
    return try {
52
    return try {
53
        my $effective       = $c->param('effective') // 1;
53
        my $effective = $c->param('effective') // 1;
54
        my $kinds =
54
        my $kinds =
55
            defined( $c->param('rules') )
55
            defined( $c->param('rules') )
56
            ? [ split /\s*,\s*/, $c->param('rules') ]
56
            ? [ split /\s*,\s*/, $c->param('rules') ]
Lines 157-162 sub list_rules { Link Here
157
157
158
        }
158
        }
159
159
160
        # Map context into rules
161
        @{$rules} = map {
162
            my %new_rule = %$_;
163
            my %context  = (
164
                "library_id"         => delete $new_rule{"branchcode"}   // "*",
165
                "patron_category_id" => delete $new_rule{"categorycode"} // "*",
166
                "item_type_id"       => delete $new_rule{"itemtype"}     // "*",
167
            );
168
            $new_rule{"context"} = \%context;
169
            \%new_rule;
170
        } @{$rules};
171
160
        return $c->render(
172
        return $c->render(
161
            status  => 200,
173
            status  => 200,
162
            openapi => $rules
174
            openapi => $rules
(-)a/api/v1/swagger/definitions/circulation_rules.yaml (+19 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  context:
5
    type: object
6
    properties:
7
      patron_category_id:
8
        type: string
9
        description: Patron category id
10
      library_id:
11
        type: string
12
        description: Library branch id
13
      item_type_id:
14
        type: string
15
        description: Item type id
16
    description: Context of the ruleset
17
additionalProperties: true
18
required:
19
  - context
(-)a/api/v1/swagger/paths/circulation_rules.yaml (-1 / +1 lines)
Lines 40-46 Link Here
40
        schema:
40
        schema:
41
          type: array
41
          type: array
42
          items:
42
          items:
43
            type: object
43
            $ref: "../swagger.yaml#/definitions/circulation_rules"
44
      "400":
44
      "400":
45
        description: Bad request
45
        description: Bad request
46
        schema:
46
        schema:
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 12-17 definitions: Link Here
12
    $ref: ./definitions/authorised_value.yaml
12
    $ref: ./definitions/authorised_value.yaml
13
  authorised_value_category:
13
  authorised_value_category:
14
    $ref: ./definitions/authorised_value_category.yaml
14
    $ref: ./definitions/authorised_value_category.yaml
15
  circulation_rules:
16
    $ref: ./definitions/circulation_rules.yaml
15
  identity_provider:
17
  identity_provider:
16
    $ref: ./definitions/identity_provider.yaml
18
    $ref: ./definitions/identity_provider.yaml
17
  identity_provider_domain:
19
  identity_provider_domain:
(-)a/t/db_dependent/api/v1/circulation_rules.t (-9 / +12 lines)
Lines 143-150 subtest 'list_rules() tests' => sub { Link Here
143
        ->json_is( '/0/finedays' => 5, "Default finedays rule returned when no library is added to request query" );
143
        ->json_is( '/0/finedays' => 5, "Default finedays rule returned when no library is added to request query" );
144
144
145
    # Limit to only rules we're interested in
145
    # Limit to only rules we're interested in
146
    $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules=fine,finedays")->status_is(200)
146
    $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules=fine,finedays")->status_is(200)->json_is(
147
        ->json_is( '/0' => { fine => 2, finedays => 5 }, "Only the two rules we asked for are returned" );
147
        '/0' => {
148
            context => { item_type_id => '*', patron_category_id => '*', library_id => '*' }, fine => 2, finedays => 5
149
        },
150
        "Only the two rules we asked for are returned"
151
    );
148
152
149
    # Warn on unsupported query parameter
153
    # Warn on unsupported query parameter
150
    $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")->status_is(400)
154
    $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")->status_is(400)
Lines 236-244 subtest 'list_rules() tests' => sub { Link Here
236
240
237
            # First rule set should march default, default, default
241
            # First rule set should march default, default, default
238
            if ( $index == 0 ) {
242
            if ( $index == 0 ) {
239
                ok(        $pointer->get('/branchcode') eq "*"
243
                ok(        $pointer->get('/context/library_id') eq "*"
240
                        && $pointer->get('/itemtype') eq '*'
244
                        && $pointer->get('/context/item_type_id') eq '*'
241
                        && $pointer->get('/categorycode') eq '*', "Default rules returned first" );
245
                        && $pointer->get('/context/patron_category_id') eq '*', "Default rules returned first" );
242
            }
246
            }
243
247
244
            # Iterate over the list of expected keys for each hash
248
            # Iterate over the list of expected keys for each hash
Lines 265-273 subtest 'list_rules() tests' => sub { Link Here
265
269
266
            # First (and only) rule set should match branchcode, default, default.
270
            # First (and only) rule set should match branchcode, default, default.
267
            if ( $index == 0 ) {
271
            if ( $index == 0 ) {
268
                ok(        $pointer->get('/branchcode') eq $branchcode
272
                ok(        $pointer->get('/context/library_id') eq $branchcode
269
                        && $pointer->get('/itemtype') eq '*'
273
                        && $pointer->get('/context/item_type_id') eq '*'
270
                        && $pointer->get('/categorycode') eq '*', "Branchcode rule set returned when filtered" );
274
                        && $pointer->get('/context/patron_category_id') eq '*', "Branchcode rule set returned when filtered" );
271
            }
275
            }
272
276
273
            # Iterate over the list of expected keys for each hash
277
            # Iterate over the list of expected keys for each hash
274
- 

Return to bug 37256