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

(-)a/Koha/Item/Transfer/Limit.pm (-1 / +1 lines)
Lines 44-50 sub to_api_mapping { Link Here
44
        limitId    => 'limit_id',
44
        limitId    => 'limit_id',
45
        toBranch   => 'to_library_id',
45
        toBranch   => 'to_library_id',
46
        fromBranch => 'from_library_id',
46
        fromBranch => 'from_library_id',
47
        itemtype   => 'item_type',
47
        itemtype   => 'item_type_id',
48
        ccode      => 'collection_code',
48
        ccode      => 'collection_code',
49
    };
49
    };
50
}
50
}
(-)a/Koha/REST/V1/TransferLimits.pm (-6 / +6 lines)
Lines 126-149 sub batch_add { Link Here
126
    return try {
126
    return try {
127
        my $params = $c->req->json;
127
        my $params = $c->req->json;
128
128
129
        if ( $params->{item_type} && $params->{collection_code} ) {
129
        if ( $params->{item_type_id} && $params->{collection_code} ) {
130
            return $c->render(
130
            return $c->render(
131
                status  => 400,
131
                status  => 400,
132
                openapi => {
132
                openapi => {
133
                    error => "You can only pass 'item_type' or 'collection_code' at a time",
133
                    error => "You can only pass 'item_type_id' or 'collection_code' at a time",
134
                }
134
                }
135
            );
135
            );
136
        }
136
        }
137
137
138
        if (   ( C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' && $params->{collection_code} )
138
        if (   ( C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' && $params->{collection_code} )
139
            || ( C4::Context->preference("BranchTransferLimitsType") eq 'ccode' && $params->{item_type} ) )
139
            || ( C4::Context->preference("BranchTransferLimitsType") eq 'ccode' && $params->{item_type_id} ) )
140
        {
140
        {
141
            return $c->render(
141
            return $c->render(
142
                status  => 409,
142
                status  => 409,
143
                openapi => {
143
                openapi => {
144
                    error => $params->{collection_code}
144
                    error => $params->{collection_code}
145
                    ? "You passed 'collection_code' but configuration expects 'item_type'"
145
                    ? "You passed 'collection_code' but configuration expects 'item_type_id'"
146
                    : "You passed 'item_type' but configuration expects 'collection_code'"
146
                    : "You passed 'item_type_id' but configuration expects 'collection_code'"
147
                }
147
                }
148
            );
148
            );
149
        }
149
        }
Lines 178-184 sub batch_add { Link Here
178
178
179
                my $key = sprintf(
179
                my $key = sprintf(
180
                    "%s:%s:%s:%s", $limit_params->{from_branch_id} || q{},
180
                    "%s:%s:%s:%s", $limit_params->{from_branch_id} || q{},
181
                    $limit_params->{to_branch_id} || q{}, $limit_params->{item_type} || q{},
181
                    $limit_params->{to_branch_id} || q{}, $limit_params->{item_type_id} || q{},
182
                    $limit_params->{collection_code} || q{}
182
                    $limit_params->{collection_code} || q{}
183
                );
183
                );
184
                next if exists $existing_limits{$key};
184
                next if exists $existing_limits{$key};
(-)a/api/v1/swagger/definitions/transfer_limit.yaml (-2 / +2 lines)
Lines 10-20 properties: Link Here
10
  from_library_id:
10
  from_library_id:
11
    type: string
11
    type: string
12
    description: Internal library id for which library the item is coming from
12
    description: Internal library id for which library the item is coming from
13
  item_type:
13
  item_type_id:
14
    type:
14
    type:
15
      - string
15
      - string
16
      - "null"
16
      - "null"
17
    description: Itemtype defining the type for this limi
17
    description: Itemtype defining the type for this limit
18
  collection_code:
18
  collection_code:
19
    type:
19
    type:
20
      - string
20
      - string
(-)a/api/v1/swagger/paths/transfer_limits.yaml (-14 / +14 lines)
Lines 17-25 Link Here
17
        description: Search on from_library_id
17
        description: Search on from_library_id
18
        required: false
18
        required: false
19
        type: string
19
        type: string
20
      - name: item_type
20
      - name: item_type_id
21
        in: query
21
        in: query
22
        description: Search on item_type
22
        description: Search on item_type_id
23
        required: false
23
        required: false
24
        type: string
24
        type: string
25
      - name: collection_code
25
      - name: collection_code
Lines 179-195 Link Here
179
179
180
      This resource batch creates new transfer limits based on the given data.
180
      This resource batch creates new transfer limits based on the given data.
181
181
182
      Transfer limits can be defined based on `collection_code` or `item_type`. The endpoint
182
      Transfer limits can be defined based on `collection_code` or `item_type_id`. The endpoint
183
      only accepts one at a time, and which one is used will depend on the value of the
183
      only accepts one at a time, and which one is used will depend on the value of the
184
      `BranchTransferLimitsType` system preference.
184
      `BranchTransferLimitsType` system preference.
185
185
186
      For example, if the paramters `to_library_id: 'BranchA'` and `item_type: 'BOOK'` are passed in
186
      For example, if the paramters `to_library_id: 'BranchA'` and `item_type_id: 'BOOK'` are passed in
187
      new transfer limits for `BOOK`s will be created, with one transfer limit each for all the
187
      new transfer limits for `BOOK`s will be created, with one transfer limit each for all the
188
      branches defined in Koha. Given 4 branches, 3 limits would be created:
188
      branches defined in Koha. Given 4 branches, 3 limits would be created:
189
189
190
      * to_library_id: 'BranchA', from_library_id: 'BranchB', item_type: 'BOOK'
190
      * to_library_id: 'BranchA', from_library_id: 'BranchB', item_type_id: 'BOOK'
191
      * to_library_id: 'BranchA', from_library_id: 'BranchC', item_type: 'BOOK'
191
      * to_library_id: 'BranchA', from_library_id: 'BranchC', item_type_id: 'BOOK'
192
      * to_library_id: 'BranchA', from_library_id: 'BranchD', item_type: 'BOOK'
192
      * to_library_id: 'BranchA', from_library_id: 'BranchD', item_type_id: 'BOOK'
193
193
194
194
195
      The body of the query would look like
195
      The body of the query would look like
Lines 197-215 Link Here
197
      ```
197
      ```
198
      {
198
      {
199
          'to_library_id': 'BranchA',
199
          'to_library_id': 'BranchA',
200
          'item_type': 'BOOK'
200
          'item_type_id': 'BOOK'
201
201
202
      }
202
      }
203
      ```
203
      ```
204
204
205
      As another example, imagine we have an itemtype that is never supposed to be transferred to another library.
205
      As another example, imagine we have an itemtype that is never supposed to be transferred to another library.
206
      If we call that itemtype `LOCAL_ONLY` we would need to just pass `item_type: 'LOCAL_ONLY'`, which would create transfer
206
      If we call that itemtype `LOCAL_ONLY` we would need to just pass `item_type_id: 'LOCAL_ONLY'`, which would create transfer
207
      limits for all libraries, meaning those items would never be allowed to transfer to another
207
      limits for all libraries, meaning those items would never be allowed to transfer to another
208
      library. The body of the query would look like
208
      library. The body of the query would look like
209
209
210
      ```
210
      ```
211
      {
211
      {
212
          'item_type': 'LOCAL_ONLY'
212
          'item_type_id': 'LOCAL_ONLY'
213
      }
213
      }
214
      ```
214
      ```
215
    tags:
215
    tags:
Lines 229-239 Link Here
229
            from_library_id:
229
            from_library_id:
230
              type: string
230
              type: string
231
              description: Internal library id for which library the item is coming from
231
              description: Internal library id for which library the item is coming from
232
            item_type:
232
            item_type_id:
233
              type:
233
              type:
234
                - string
234
                - string
235
                - "null"
235
                - "null"
236
              description: Itemtype defining the type for this limi
236
              description: Itemtype defining the type for this limit
237
            collection_code:
237
            collection_code:
238
              type:
238
              type:
239
                - string
239
                - string
Lines 303-313 Link Here
303
            from_library_id:
303
            from_library_id:
304
              type: string
304
              type: string
305
              description: Internal library id for which library the item is coming from
305
              description: Internal library id for which library the item is coming from
306
            item_type:
306
            item_type_id:
307
              type:
307
              type:
308
                - string
308
                - string
309
                - "null"
309
                - "null"
310
              description: Itemtype defining the type for this limi
310
              description: Itemtype defining the type for this limit
311
            collection_code:
311
            collection_code:
312
              type:
312
              type:
313
                - string
313
                - string
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/transfer_limits.tt (-1 / +1 lines)
Lines 148-154 Link Here
148
    [% INCLUDE 'datatables.inc' %]
148
    [% INCLUDE 'datatables.inc' %]
149
    <script>
149
    <script>
150
        const branchTransferLimitsType = "[% BranchTransferLimitsType | html %]";
150
        const branchTransferLimitsType = "[% BranchTransferLimitsType | html %]";
151
        const val_type = branchTransferLimitsType == "itemtype" ? "item_type" : "collection_code";
151
        const val_type = branchTransferLimitsType == "itemtype" ? "item_type_id" : "collection_code";
152
        const branches = [% To.json(branches) | $raw %];
152
        const branches = [% To.json(branches) | $raw %];
153
153
154
        $('#loading_limits').hide();
154
        $('#loading_limits').hide();
(-)a/t/db_dependent/api/v1/transfer_limits.t (-7 / +8 lines)
Lines 196-202 subtest 'batch_add() and batch_delete() tests' => sub { Link Here
196
    $unauthorized_patron->set_password( { password => $password, skip_validation => 1 } );
196
    $unauthorized_patron->set_password( { password => $password, skip_validation => 1 } );
197
    my $unauth_userid = $unauthorized_patron->userid;
197
    my $unauth_userid = $unauthorized_patron->userid;
198
198
199
    my $limit_hashref = { item_type => $itemtype->id };
199
    my $limit_hashref = { item_type_id => $itemtype->id };
200
200
201
    # Unauthorized attempt to write
201
    # Unauthorized attempt to write
202
    $t->post_ok( "//$unauth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref )->status_is(403);
202
    $t->post_ok( "//$unauth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref )->status_is(403);
Lines 216-235 subtest 'batch_add() and batch_delete() tests' => sub { Link Here
216
216
217
    # Create all combinations of to/from libraries
217
    # Create all combinations of to/from libraries
218
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json =>
218
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json =>
219
            { item_type => 'X', collection_code => 'Y' } )->status_is(400)
219
            { item_type_id => 'X', collection_code => 'Y' } )->status_is(400)
220
        ->json_is( '/error' => "You can only pass 'item_type' or 'collection_code' at a time" );
220
        ->json_is( '/error' => "You can only pass 'item_type_id' or 'collection_code' at a time" );
221
221
222
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'ccode' );
222
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'ccode' );
223
223
224
    # Create all combinations of to/from libraries
224
    # Create all combinations of to/from libraries
225
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { item_type => 'X' } )
225
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { item_type_id => 'X' } )
226
        ->status_is(409)->json_is( '/error' => "You passed 'item_type' but configuration expects 'collection_code'" );
226
        ->status_is(409)
227
        ->json_is( '/error' => "You passed 'item_type_id' but configuration expects 'collection_code'" );
227
228
228
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
229
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
229
230
230
    # Create all combinations of to/from libraries
231
    # Create all combinations of to/from libraries
231
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { collection_code => 'X' } )
232
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { collection_code => 'X' } )
232
        ->status_is(409)->json_is( '/error' => "You passed 'collection_code' but configuration expects 'item_type'" );
233
        ->status_is(409)
234
        ->json_is( '/error' => "You passed 'collection_code' but configuration expects 'item_type_id'" );
233
235
234
    # Create all combinations of to/from libraries
236
    # Create all combinations of to/from libraries
235
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref )
237
    $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref )
236
- 

Return to bug 41530