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

(-)a/Koha/REST/V1/Holds.pm (-4 / +4 lines)
Lines 80-85 sub add { Link Here
80
        my $hold_date         = $body->{hold_date};
80
        my $hold_date         = $body->{hold_date};
81
        my $non_priority      = $body->{non_priority};
81
        my $non_priority      = $body->{non_priority};
82
82
83
        my $overrides = $c->stash('koha.overrides');
84
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
85
83
        if(!C4::Context->preference( 'AllowHoldDateInFuture' ) && $hold_date) {
86
        if(!C4::Context->preference( 'AllowHoldDateInFuture' ) && $hold_date) {
84
            return $c->render(
87
            return $c->render(
85
                status  => 400,
88
                status  => 400,
Lines 160-166 sub add { Link Here
160
            openapi => {
163
            openapi => {
161
                error => 'The supplied pickup location is not valid'
164
                error => 'The supplied pickup location is not valid'
162
            }
165
            }
163
        ) unless $valid_pickup_location;
166
        ) unless $valid_pickup_location || $can_override;
164
167
165
        my $can_place_hold
168
        my $can_place_hold
166
            = $item_id
169
            = $item_id
Lines 171-179 sub add { Link Here
171
            $can_place_hold->{status} = 'tooManyReserves';
174
            $can_place_hold->{status} = 'tooManyReserves';
172
        }
175
        }
173
176
174
        my $overrides = $c->stash('koha.overrides');
175
        my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
176
177
        unless ( $can_override || $can_place_hold->{status} eq 'OK' ) {
177
        unless ( $can_override || $can_place_hold->{status} eq 'OK' ) {
178
            return $c->render(
178
            return $c->render(
179
                status => 403,
179
                status => 403,
(-)a/t/db_dependent/api/v1/holds.t (-4 / +15 lines)
Lines 358-364 $schema->storage->txn_rollback; Link Here
358
358
359
subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub {
359
subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub {
360
360
361
    plan tests => 12;
361
    plan tests => 16;
362
362
363
    $schema->storage->txn_begin;
363
    $schema->storage->txn_begin;
364
364
Lines 373-387 subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { Link Here
373
    $patron->discard_changes;
373
    $patron->discard_changes;
374
    my $userid = $patron->userid;
374
    my $userid = $patron->userid;
375
375
376
    my $renegade_library = $builder->build_object({ class => 'Koha::Libraries' });
377
376
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
378
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
377
379
378
    # Make sure pickup location checks doesn't get in the middle
380
    # Make sure pickup location checks doesn't get in the middle
379
    my $mock_biblio = Test::MockModule->new('Koha::Biblio');
381
    my $mock_biblio = Test::MockModule->new('Koha::Biblio');
380
    $mock_biblio->mock( 'pickup_locations',
382
    $mock_biblio->mock( 'pickup_locations',
381
        sub { return Koha::Libraries->search; } );
383
        sub { return Koha::Libraries->search({ branchcode => { '!=' => $renegade_library->branchcode } }); } );
382
    my $mock_item = Test::MockModule->new('Koha::Item');
384
    my $mock_item = Test::MockModule->new('Koha::Item');
383
    $mock_item->mock( 'pickup_locations',
385
    $mock_item->mock( 'pickup_locations',
384
        sub { return Koha::Libraries->search } );
386
        sub { return Koha::Libraries->search({ branchcode => { '!=' => $renegade_library->branchcode } }) } );
385
387
386
    my $can_item_be_reserved_result;
388
    my $can_item_be_reserved_result;
387
    my $mock_reserves = Test::MockModule->new('C4::Reserves');
389
    my $mock_reserves = Test::MockModule->new('C4::Reserves');
Lines 433-438 subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { Link Here
433
          { 'x-koha-override' => 'any' } => json => $post_data )
435
          { 'x-koha-override' => 'any' } => json => $post_data )
434
      ->status_is(201);
436
      ->status_is(201);
435
437
438
    # Test pickup locations can be overridden
439
    $post_data->{pickup_library_id} = $renegade_library->branchcode;
440
441
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
442
      ->status_is(400);
443
444
    $t->post_ok( "//$userid:$password@/api/v1/holds" =>
445
          { 'x-koha-override' => 'any' } => json => $post_data )
446
      ->status_is(201);
447
436
    $schema->storage->txn_rollback;
448
    $schema->storage->txn_rollback;
437
};
449
};
438
450
439
- 

Return to bug 27797