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

(-)a/Koha/REST/V1/ILL/Requests.pm (-14 / +30 lines)
Lines 60-91 sub list { Link Here
60
60
61
=head3 patron_list
61
=head3 patron_list
62
62
63
Controller function that handles listing Koha::ILL::Request objects for a given patron.
63
Controller function that returns a patron's list of ILL requests.
64
65
The patron must match the requesting user unless the requesting user is a superlibrarian.
66
67
This is a public route, so some request details are omitted.
68
64
69
=cut
65
=cut
70
66
71
sub patron_list {
67
sub patron_list {
72
    my $c    = shift->openapi->valid_input or return;
68
    my $c = shift->openapi->valid_input or return;
73
    my $user = $c->stash('koha.user');
69
74
    $c->stash( is_public => 1 );
70
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
71
72
    return $c->render_resource_not_found('Patron')
73
        unless $patron;
74
75
    return try {
75
76
76
    if ( $user->borrowernumber != $c->param('patron_id') and !$user->is_superlibrarian ) {
77
        return $c->render(
77
        return $c->render(
78
            status  => 403,
78
            status  => 200,
79
            openapi => { error => "Cannot lookup ILL requests for other users" }
79
            openapi => $c->objects->search( $patron->ill_requests ),
80
        );
80
        );
81
    }
81
    } catch {
82
        $c->unhandled_exception($_);
83
    };
84
}
85
86
=head3 public_patron_list
87
88
Controller function that returns a patron's list of ILL requests for unprivileged
89
access.
90
91
=cut
92
93
sub public_patron_list {
94
    my $c = shift->openapi->valid_input or return;
82
95
83
    return try {
96
    return try {
84
        my $reqs = $c->objects->search( Koha::ILL::Requests->search( { borrowernumber => $c->param('patron_id') } ) );
97
98
        $c->auth->public( $c->param('patron_id') );
99
100
        my $patron = $c->stash('koha.user');
85
101
86
        return $c->render(
102
        return $c->render(
87
            status  => 200,
103
            status  => 200,
88
            openapi => $reqs,
104
            openapi => $c->objects->search( $patron->ill_requests() ),
89
        );
105
        );
90
    } catch {
106
    } catch {
91
        $c->unhandled_exception($_);
107
        $c->unhandled_exception($_);
(-)a/api/v1/swagger/paths/patrons.yaml (-2 / +2 lines)
Lines 667-673 Link Here
667
    x-mojo-to: ILL::Requests#patron_list
667
    x-mojo-to: ILL::Requests#patron_list
668
    operationId: getPatronIllRequests
668
    operationId: getPatronIllRequests
669
    tags:
669
    tags:
670
      - patrons
671
      - ill_requests
670
      - ill_requests
672
    summary: Get patron's ILL requests
671
    summary: Get patron's ILL requests
673
    parameters:
672
    parameters:
Lines 727-730 Link Here
727
        schema:
726
        schema:
728
          $ref: "../swagger.yaml#/definitions/error"
727
          $ref: "../swagger.yaml#/definitions/error"
729
    x-koha-authorization:
728
    x-koha-authorization:
730
      permissions: {}
729
      permissions:
730
        ill: "1"
(-)a/api/v1/swagger/paths/public_patrons.yaml (-2 / +67 lines)
Lines 277-280 Link Here
277
      "503":
277
      "503":
278
        description: Under maintenance
278
        description: Under maintenance
279
        schema:
279
        schema:
280
          $ref: "../swagger.yaml#/definitions/error"
280
          $ref: "../swagger.yaml#/definitions/error"
281
"/public/patrons/{patron_id}/ill/requests":
282
  get:
283
    x-mojo-to: ILL::Requests#public_patron_list
284
    operationId: getPatronIllRequests
285
    tags:
286
      - ill_requests
287
    summary: Get patron's ILL requests
288
    parameters:
289
      - $ref: "../swagger.yaml#/parameters/patron_id_pp"
290
      - $ref: "../swagger.yaml#/parameters/page"
291
      - $ref: "../swagger.yaml#/parameters/per_page"
292
      - $ref: "../swagger.yaml#/parameters/match"
293
      - $ref: "../swagger.yaml#/parameters/order_by"
294
      - $ref: "../swagger.yaml#/parameters/q_param"
295
      - $ref: "../swagger.yaml#/parameters/q_body"
296
      - $ref: "../swagger.yaml#/parameters/request_id_header"
297
      - name: x-koha-embed
298
        in: header
299
        required: false
300
        description: Embed list sent as a request header
301
        type: array
302
        items:
303
          type: string
304
          enum:
305
            - +strings
306
            - extended_attributes
307
        collectionFormat: csv
308
    produces:
309
      - application/json
310
    responses:
311
      "200":
312
        description: A list of parton's ILL requests
313
        schema:
314
          type: array
315
          items:
316
            $ref: "../swagger.yaml#/definitions/ill_request"
317
      "400":
318
        description: Bad request
319
        schema:
320
          $ref: "../swagger.yaml#/definitions/error"
321
      "401":
322
        description: Authentication required
323
        schema:
324
          $ref: "../swagger.yaml#/definitions/error"
325
      "403":
326
        description: Access forbidden
327
        schema:
328
          $ref: "../swagger.yaml#/definitions/error"
329
      "404":
330
        description: Patron not found
331
        schema:
332
          $ref: "../swagger.yaml#/definitions/error"
333
      "500":
334
        description: |
335
          Internal server error. Possible `error_code` attribute values:
336
337
          * `internal_server_error`
338
        schema:
339
          $ref: "../swagger.yaml#/definitions/error"
340
      "503":
341
        description: Under maintenance
342
        schema:
343
          $ref: "../swagger.yaml#/definitions/error"
344
    x-koha-authorization:
345
      permissions:
346
        ill: "1"
281
- 

Return to bug 38340