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

(-)a/Koha/REST/V1/Holds.pm (+32 lines)
Lines 433-436 sub pickup_locations { Link Here
433
    };
433
    };
434
}
434
}
435
435
436
=head3 update_pickup_location
437
438
Method that handles modifying the pickup location of a Koha::Hold object
439
440
=cut
441
442
sub update_pickup_location {
443
    my $c = shift->openapi->valid_input or return;
444
445
    my $hold_id = $c->validation->param('hold_id');
446
    my $hold = Koha::Holds->find($hold_id);
447
448
    unless ($hold) {
449
        return $c->render(
450
            status  => 404,
451
            openapi => { error => "Hold not found" }
452
        );
453
    }
454
455
    return try {
456
        my $pickup_location = $c->req->json;
457
458
        $hold->branchcode($pickup_location)->store;
459
460
        return $c->render( status => 200, openapi => $pickup_location );
461
    }
462
    catch {
463
        $c->unhandled_exception($_);
464
    };
465
}
466
467
436
1;
468
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 / +52 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 10;
20
use Test::More tests => 11;
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 787-789 subtest 'pickup_locations() tests' => sub { Link Here
787
787
788
    $schema->storage->txn_rollback;
788
    $schema->storage->txn_rollback;
789
};
789
};
790
- 
790
791
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
792
793
    plan tests => 4;
794
795
    $schema->storage->txn_begin;
796
797
    my $password = 'AbcdEFG123';
798
799
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
800
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
801
802
    my $patron = $builder->build_object(
803
        { class => 'Koha::Patrons', value => { flags => 0 } } );
804
    $patron->set_password( { password => $password, skip_validation => 1 } );
805
    my $userid = $patron->userid;
806
    $builder->build(
807
        {
808
            source => 'UserPermission',
809
            value  => {
810
                borrowernumber => $patron->borrowernumber,
811
                module_bit     => 6,
812
                code           => 'place_holds',
813
            },
814
        }
815
    );
816
817
    # Disable logging
818
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
819
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
820
821
    my $biblio = $builder->build_sample_biblio;
822
    my $hold = Koha::Holds->find(
823
        AddReserve(
824
            {
825
                branchcode     => $library_1->branchcode,
826
                borrowernumber => $patron->borrowernumber,
827
                biblionumber   => $biblio->biblionumber,
828
                priority       => 1,
829
            }
830
        )
831
    );
832
833
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
834
          . $hold->id
835
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
836
837
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
838
839
    $schema->storage->txn_rollback;
840
};

Return to bug 18729