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

(-)a/Koha/REST/V1/Holds.pm (+32 lines)
Lines 475-478 sub pickup_locations { Link Here
475
    };
475
    };
476
}
476
}
477
477
478
=head3 update_pickup_location
479
480
Method that handles modifying the pickup location of a Koha::Hold object
481
482
=cut
483
484
sub update_pickup_location {
485
    my $c = shift->openapi->valid_input or return;
486
487
    my $hold_id = $c->validation->param('hold_id');
488
    my $hold = Koha::Holds->find($hold_id);
489
490
    unless ($hold) {
491
        return $c->render(
492
            status  => 404,
493
            openapi => { error => "Hold not found" }
494
        );
495
    }
496
497
    return try {
498
        my $pickup_location = $c->req->json;
499
500
        $hold->branchcode($pickup_location)->store;
501
502
        return $c->render( status => 200, openapi => $pickup_location );
503
    }
504
    catch {
505
        $c->unhandled_exception($_);
506
    };
507
}
508
509
478
1;
510
1;
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 62-67 Link Here
62
  "/holds/{hold_id}/pickup_locations": {
62
  "/holds/{hold_id}/pickup_locations": {
63
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
63
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
64
  },
64
  },
65
  "/holds/{hold_id}/pickup_location": {
66
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_location"
67
  },
65
  "/items": {
68
  "/items": {
66
    "$ref": "paths/items.json#/~1items"
69
    "$ref": "paths/items.json#/~1items"
67
  },
70
  },
(-)a/api/v1/swagger/paths/holds.json (+73 lines)
Lines 676-680 Link Here
676
        }
676
        }
677
      }
677
      }
678
    }
678
    }
679
  },
680
  "/holds/{hold_id}/pickup_location": {
681
    "put": {
682
      "x-mojo-to": "Holds#update_pickup_location",
683
      "operationId": "updateHoldPickupLocation",
684
      "tags": ["holds"],
685
      "parameters": [
686
        {
687
          "$ref": "../parameters.json#/hold_id_pp"
688
        },
689
        {
690
          "name": "body",
691
          "in": "body",
692
          "description": "Pickup location",
693
          "required": true,
694
          "schema": {
695
            "type": "string"
696
          }
697
        }
698
      ],
699
      "produces": [
700
        "application/json"
701
      ],
702
      "responses": {
703
        "200": {
704
          "description": "The new pickup location value for the hold",
705
          "schema": {
706
            "type": "string"
707
          }
708
        },
709
        "401": {
710
          "description": "Authentication required",
711
          "schema": {
712
            "$ref": "../definitions.json#/error"
713
          }
714
        },
715
        "403": {
716
          "description": "Access forbidden",
717
          "schema": {
718
            "$ref": "../definitions.json#/error"
719
          }
720
        },
721
        "404": {
722
          "description": "Hold not found",
723
          "schema": {
724
            "$ref": "../definitions.json#/error"
725
          }
726
        },
727
        "409": {
728
          "description": "Unable to perform action on hold",
729
          "schema": {
730
            "$ref": "../definitions.json#/error"
731
          }
732
        },
733
        "500": {
734
          "description": "Internal error",
735
          "schema": {
736
            "$ref": "../definitions.json#/error"
737
          }
738
        },
739
        "503": {
740
          "description": "Under maintenance",
741
          "schema": {
742
            "$ref": "../definitions.json#/error"
743
          }
744
        }
745
      },
746
      "x-koha-authorization": {
747
        "permissions": {
748
          "reserveforothers": "place_holds"
749
        }
750
      }
751
    }
679
  }
752
  }
680
}
753
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-3 / +2 lines)
Lines 224-235 $(document).ready(function() { Link Here
224
                    var cur_select = $(this);
224
                    var cur_select = $(this);
225
                    var res_id = $(this).attr('reserve_id');
225
                    var res_id = $(this).attr('reserve_id');
226
                    $(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>');
226
                    $(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>');
227
                    var api_url = '/api/v1/holds/'+res_id;
227
                    var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location';
228
                    var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
229
                    $.ajax({
228
                    $.ajax({
230
                        method: "PUT",
229
                        method: "PUT",
231
                        url: api_url,
230
                        url: api_url,
232
                        data: update_info ,
231
                        data: $(this).val(),
233
                        success: function( data ){ holdsTable.api().ajax.reload(); },
232
                        success: function( data ){ holdsTable.api().ajax.reload(); },
234
                        error: function( jqXHR, textStatus, errorThrown) {
233
                        error: function( jqXHR, textStatus, errorThrown) {
235
                            alert('There was an error:'+textStatus+" "+errorThrown);
234
                            alert('There was an error:'+textStatus+" "+errorThrown);
(-)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 => 12;
20
use Test::More tests => 13;
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 1011-1013 subtest 'add() tests' => sub { Link Here
1011
1011
1012
    $schema->storage->txn_rollback;
1012
    $schema->storage->txn_rollback;
1013
};
1013
};
1014
- 
1014
1015
1016
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
1017
1018
    plan tests => 4;
1019
1020
    $schema->storage->txn_begin;
1021
1022
    my $password = 'AbcdEFG123';
1023
1024
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
1025
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1026
1027
    my $patron = $builder->build_object(
1028
        { class => 'Koha::Patrons', value => { flags => 0 } } );
1029
    $patron->set_password( { password => $password, skip_validation => 1 } );
1030
    my $userid = $patron->userid;
1031
    $builder->build(
1032
        {
1033
            source => 'UserPermission',
1034
            value  => {
1035
                borrowernumber => $patron->borrowernumber,
1036
                module_bit     => 6,
1037
                code           => 'place_holds',
1038
            },
1039
        }
1040
    );
1041
1042
    # Disable logging
1043
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1044
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1045
1046
    my $biblio = $builder->build_sample_biblio;
1047
    my $hold = Koha::Holds->find(
1048
        AddReserve(
1049
            {
1050
                branchcode     => $library_1->branchcode,
1051
                borrowernumber => $patron->borrowernumber,
1052
                biblionumber   => $biblio->biblionumber,
1053
                priority       => 1,
1054
            }
1055
        )
1056
    );
1057
1058
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1059
          . $hold->id
1060
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
1061
1062
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1063
1064
    $schema->storage->txn_rollback;
1065
};

Return to bug 18729