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

(-)a/Koha/REST/V1/Holds.pm (+24 lines)
Lines 561-564 sub update_pickup_location { Link Here
561
    };
561
    };
562
}
562
}
563
563
564
=head3 lowest_priority
565
566
Method that handles toggling the lowest priority of a Koha::Hold object
567
568
=cut
569
570
sub lowest_priority {
571
    my $c = shift->openapi->valid_input or return;
572
573
    my $hold_id = $c->param('hold_id');
574
    my $hold    = Koha::Holds->find($hold_id);
575
576
    return $c->render_resource_not_found("Hold")
577
        unless $hold;
578
579
    return try {
580
        C4::Reserves::ToggleLowestPriority($hold_id);
581
        $hold->discard_changes;    # refresh
582
        return $c->render( status => 200, openapi => $hold_id );
583
    } catch {
584
        $c->unhandled_exception($_);
585
    };
586
}
587
564
1;
588
1;
(-)a/api/v1/swagger/paths/holds.yaml (+51 lines)
Lines 761-763 Link Here
761
    x-koha-authorization:
761
    x-koha-authorization:
762
      permissions:
762
      permissions:
763
        reserveforothers: place_holds
763
        reserveforothers: place_holds
764
"/holds/{hold_id}/lowest_priority":
765
  put:
766
    x-mojo-to: Holds#lowest_priority
767
    operationId: toggleLowestPriority
768
    tags:
769
      - holds
770
    summary: Toggle holds lowest priority
771
    parameters:
772
      - $ref: "../swagger.yaml#/parameters/hold_id_pp"
773
      - name: body
774
        in: body
775
        description: An integer representing the new priority to be set for the hold
776
        required: false
777
        schema:
778
          type: integer
779
    produces:
780
      - application/json
781
    responses:
782
      "200":
783
        description: Toggle the holds lowest priority value
784
        schema:
785
          type: integer
786
      "401":
787
        description: Authentication required
788
        schema:
789
          $ref: "../swagger.yaml#/definitions/error"
790
      "403":
791
        description: Access forbidden
792
        schema:
793
          $ref: "../swagger.yaml#/definitions/error"
794
      "404":
795
        description: Hold not found
796
        schema:
797
          $ref: "../swagger.yaml#/definitions/error"
798
      "409":
799
        description: Unable to perform action on hold
800
        schema:
801
          $ref: "../swagger.yaml#/definitions/error"
802
      "500":
803
        description: |
804
          Internal server error. Possible `error_code` attribute values:
805
          * `internal_server_error`
806
        schema:
807
          $ref: "../swagger.yaml#/definitions/error"
808
      "503":
809
        description: Under maintenance
810
        schema:
811
          $ref: "../swagger.yaml#/definitions/error"
812
    x-koha-authorization:
813
      permissions:
814
        reserveforothers: modify_holds_priority
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 397-402 paths: Link Here
397
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority"
397
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1priority"
398
  "/holds/{hold_id}/suspension":
398
  "/holds/{hold_id}/suspension":
399
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension"
399
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1suspension"
400
  "/holds/{hold_id}/lowest_priority":
401
    $ref: "./paths/holds.yaml#/~1holds~1{hold_id}~1lowest_priority"
400
  /ill/backends:
402
  /ill/backends:
401
    $ref: ./paths/ill_backends.yaml#/~1ill~1backends
403
    $ref: ./paths/ill_backends.yaml#/~1ill~1backends
402
  "/ill/backends/{ill_backend_id}":
404
  "/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 1575-1577 subtest 'delete() tests' => sub { Link Here
1575
1575
1576
    $schema->storage->txn_rollback;
1576
    $schema->storage->txn_rollback;
1577
};
1577
};
1578
- 
1578
1579
subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub {
1580
1581
    plan tests => 5;
1582
1583
    $schema->storage->txn_begin;
1584
1585
    my $password = 'AbcdEFG123';
1586
1587
    my $library_1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
1588
1589
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } );
1590
    $patron->set_password( { password => $password, skip_validation => 1 } );
1591
    my $userid = $patron->userid;
1592
    $builder->build(
1593
        {
1594
            source => 'UserPermission',
1595
            value  => {
1596
                borrowernumber => $patron->borrowernumber,
1597
                module_bit     => 6,
1598
                code           => 'modify_holds_priority',
1599
            },
1600
        }
1601
    );
1602
1603
    # Disable logging
1604
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1605
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1606
1607
    my $biblio = $builder->build_sample_biblio;
1608
1609
    # biblio-level hold
1610
    my $hold = Koha::Holds->find(
1611
        AddReserve(
1612
            {
1613
                branchcode     => $library_1->branchcode,
1614
                borrowernumber => $patron->borrowernumber,
1615
                biblionumber   => $biblio->biblionumber,
1616
                priority       => 1,
1617
                itemnumber     => undef,
1618
            }
1619
        )
1620
    );
1621
1622
    $t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/lowest_priority" )->status_is(404);
1623
1624
    $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/lowest_priority" )->status_is(200);
1625
1626
    is( $hold->discard_changes->lowestPriority, 1, 'Priority set to lowest' );
1627
1628
    $schema->storage->txn_rollback;
1629
};

Return to bug 38253