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

(-)a/Koha/REST/V1/Holds.pm (+24 lines)
Lines 554-557 sub update_pickup_location { Link Here
554
    };
554
    };
555
}
555
}
556
556
557
=head3 toggle_lowest_priority
558
559
Method that handles toggling the lowest priority of a Koha::Hold object
560
561
=cut
562
563
sub toggle_lowest_priority {
564
    my $c = shift->openapi->valid_input or return;
565
566
    my $hold_id = $c->param('hold_id');
567
    my $hold    = Koha::Holds->find($hold_id);
568
569
    return $c->render_resource_not_found("Hold")
570
        unless $hold;
571
572
    return try {
573
        C4::Reserves::ToggleLowestPriority($hold_id);
574
        $hold->discard_changes;    # refresh
575
        return $c->render( status => 200, openapi => $hold_id );
576
    } catch {
577
        $c->unhandled_exception($_);
578
    };
579
}
580
557
1;
581
1;
(-)a/api/v1/swagger/paths/holds.yaml (+51 lines)
Lines 747-749 Link Here
747
    x-koha-authorization:
747
    x-koha-authorization:
748
      permissions:
748
      permissions:
749
        reserveforothers: place_holds
749
        reserveforothers: place_holds
750
"/holds/{hold_id}/toggle_lowest_priority":
751
  put:
752
    x-mojo-to: Holds#toggle_lowest_priority
753
    operationId: toggleLowestPriority
754
    tags:
755
      - holds
756
    summary: Toggle holds lowest priority
757
    parameters:
758
      - $ref: "../swagger.yaml#/parameters/hold_id_pp"
759
      - name: body
760
        in: body
761
        description: An integer representing the new priority to be set for the hold
762
        required: false
763
        schema:
764
          type: integer
765
    produces:
766
      - application/json
767
    responses:
768
      "200":
769
        description: Toggle the holds lowest priority value
770
        schema:
771
          type: integer
772
      "401":
773
        description: Authentication required
774
        schema:
775
          $ref: "../swagger.yaml#/definitions/error"
776
      "403":
777
        description: Access forbidden
778
        schema:
779
          $ref: "../swagger.yaml#/definitions/error"
780
      "404":
781
        description: Hold not found
782
        schema:
783
          $ref: "../swagger.yaml#/definitions/error"
784
      "409":
785
        description: Unable to perform action on hold
786
        schema:
787
          $ref: "../swagger.yaml#/definitions/error"
788
      "500":
789
        description: |
790
          Internal server error. Possible `error_code` attribute values:
791
          * `internal_server_error`
792
        schema:
793
          $ref: "../swagger.yaml#/definitions/error"
794
      "503":
795
        description: Under maintenance
796
        schema:
797
          $ref: "../swagger.yaml#/definitions/error"
798
    x-koha-authorization:
799
      permissions:
800
        reserveforothers: modify_holds_priority
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 391-396 paths: Link Here
391
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority"
391
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority"
392
  "/holds/{hold_id}/suspension":
392
  "/holds/{hold_id}/suspension":
393
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension"
393
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension"
394
  "/holds/{hold_id}/toggle_lowest_priority":
395
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1toggle_lowest_priority"
394
  /ill/backends:
396
  /ill/backends:
395
    $ref: ./paths/ill_backends.yaml#/~1ill~1backends
397
    $ref: ./paths/ill_backends.yaml#/~1ill~1backends
396
  "/ill/backends/{ill_backend_id}":
398
  "/ill/backends/{ill_backend_id}":
(-)a/t/db_dependent/api/v1/holds.t (-2 / +53 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 14;
20
use Test::More tests => 15;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
Lines 1547-1549 subtest 'delete() tests' => sub { Link Here
1547
1547
1548
    $schema->storage->txn_rollback;
1548
    $schema->storage->txn_rollback;
1549
};
1549
};
1550
- 
1550
1551
subtest 'PUT /holds/{hold_id}/toggle_lowest_priority tests' => sub {
1552
1553
    plan tests => 5;
1554
1555
    $schema->storage->txn_begin;
1556
1557
    my $password = 'AbcdEFG123';
1558
1559
    my $library_1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
1560
1561
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
1562
    $patron->set_password( { password => $password, skip_validation => 1 } );
1563
    my $userid = $patron->userid;
1564
    $builder->build(
1565
        {
1566
            source => 'UserPermission',
1567
            value  => {
1568
                borrowernumber => $patron->borrowernumber,
1569
                module_bit     => 6,
1570
                code           => 'modify_holds_priority',
1571
            },
1572
        }
1573
    );
1574
1575
    # Disable logging
1576
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1577
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1578
1579
    my $biblio = $builder->build_sample_biblio;
1580
1581
    # biblio-level hold
1582
    my $hold = Koha::Holds->find(
1583
        AddReserve(
1584
            {
1585
                branchcode     => $library_1->branchcode,
1586
                borrowernumber => $patron->borrowernumber,
1587
                biblionumber   => $biblio->biblionumber,
1588
                priority       => 1,
1589
                itemnumber     => undef,
1590
            }
1591
        )
1592
    );
1593
1594
    $t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/toggle_lowest_priority" )->status_is(404);
1595
1596
    $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/toggle_lowest_priority" )->status_is(200);
1597
1598
    is( $hold->discard_changes->lowest_priority, 1, 'Priority set to lowest' );
1599
1600
    $schema->storage->txn_rollback;
1601
};

Return to bug 38253