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

(-)a/Koha/REST/V1/Checkouts.pm (-25 / +51 lines)
Lines 102-108 sub get { Link Here
102
    };
102
    };
103
}
103
}
104
104
105
=head3 get_availablity
105
=head3 _check_availability 
106
107
Internal function to call CanBookBeIssued and return an appropriately filtered 
108
set return
109
110
=cut
111
112
sub _check_availability {
113
    my ( $c, $patron, $item ) = @_;
114
115
    my $inprocess       = 0;                   # What does this do?
116
    my $ignore_reserves = 0;                   # Don't ignore reserves
117
    my $params          = { item => $item };
118
119
    my ( $impossible, $confirmation, $alerts, $messages ) =
120
      C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess,
121
        $ignore_reserves, $params );
122
123
    if ( $c->stash('is_public') ) {
124
125
        # Upgrade some confirmations to blockers
126
        my @should_block =
127
          qw/TOO_MANY ISSUED_TO_ANOTHER RESERVED RESERVED_WAITING TRANSFERRED PROCESSING AGE_RESTRICTION/;
128
        for my $block (@should_block) {
129
            if ( exists( $confirmation->{$block} ) ) {
130
                $impossible->{$block} = $confirmation->{$block};
131
                delete $confirmation->{$block};
132
            }
133
        }
134
135
        # Remove any non-public info that's returned by CanBookBeIssued
136
        my @restricted_keys =
137
          qw/issued_borrowernumber issued_cardnumber issued_firstname issued_surname resborrowernumber resbranchcode rescardnumber reserve_id resfirstname resreservedate ressurname item_notforloan/;
138
        for my $key (@restricted_keys) {
139
            delete $confirmation->{$key};
140
            delete $impossible->{$key};
141
            delete $alerts->{$key};
142
            delete $messages->{$key};
143
        }
144
    }
145
146
    return ( $impossible, $confirmation, { %{$alerts}, %{$messages} } );
147
}
148
149
=head3 get_availability
106
150
107
Controller function that handles retrieval of Checkout availability
151
Controller function that handles retrieval of Checkout availability
108
152
Lines 112-130 sub get_availability { Link Here
112
    my $c = shift->openapi->valid_input or return;
156
    my $c = shift->openapi->valid_input or return;
113
157
114
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
158
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
115
    my $inprocess = 0; # What does this do?
116
    my $ignore_reserves = 0; # Don't ignore reserves
117
    my $item   = Koha::Items->find( $c->validation->param('item_id') );
159
    my $item   = Koha::Items->find( $c->validation->param('item_id') );
118
    my $params = {
119
        item => $item
120
    };
121
160
122
    my ( $impossible, $confirmation, $alerts, $messages ) =
161
    my ( $impossible, $confirmation, $warnings ) =
123
      C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves,
162
      $c->_check_availability( $patron, $item );
124
        $params );
125
163
126
    my $token;
164
    my $token;
127
    if (keys %{$confirmation}) {
165
    if ( keys %{$confirmation} ) {
128
        my $claims = { map { $_ => 1 } keys %{$confirmation} };
166
        my $claims = { map { $_ => 1 } keys %{$confirmation} };
129
        my $secret =
167
        my $secret =
130
          md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) );
168
          md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) );
Lines 134-140 sub get_availability { Link Here
134
    my $response = {
172
    my $response = {
135
        blockers           => $impossible,
173
        blockers           => $impossible,
136
        confirms           => $confirmation,
174
        confirms           => $confirmation,
137
        warnings           => { %{$alerts}, %{$messages} },
175
        warnings           => $warnings,
138
        confirmation_token => $token
176
        confirmation_token => $token
139
    };
177
    };
140
178
Lines 178-197 sub add { Link Here
178
            );
216
            );
179
        }
217
        }
180
218
181
        my $inprocess       = 0;                   # What does this do?
219
        my ( $impossible, $confirmation, $warnings ) =
182
        my $ignore_reserves = 0;                   # Don't ignore reserves
220
          $c->_check_availability( $patron, $item );
183
        my $params          = { item => $item };
184
185
        # Call 'CanBookBeIssued'
186
        my ( $impossible, $confirmation, $alerts, $messages ) =
187
          C4::Circulation::CanBookBeIssued(
188
             $patron,
189
             undef,
190
             undef,
191
             $inprocess,
192
             $ignore_reserves,
193
             $params
194
        );
195
221
196
        # * Fail for blockers - render 403
222
        # * Fail for blockers - render 403
197
        if ( keys %{$impossible} ) {
223
        if ( keys %{$impossible} ) {
(-)a/api/v1/swagger/paths/checkouts.yaml (-4 / +36 lines)
Lines 89-101 Link Here
89
        description: Created checkout
89
        description: Created checkout
90
        schema:
90
        schema:
91
          $ref: "../swagger.yaml#/definitions/checkout"
91
          $ref: "../swagger.yaml#/definitions/checkout"
92
      "400":
92
      "400": 
93
        description: Missing or wrong parameters
93
        description: Missing or wrong parameters
94
        schema:
94
        schema: 
95
          $ref: "../swagger.yaml#/definitions/error"
95
          $ref: "../swagger.yaml#/definitions/error"
96
      "401":
96
      "401": 
97
        description: Authentication required
97
        description: Authentication required
98
        schema:
98
        schema: 
99
          $ref: "../swagger.yaml#/definitions/error"
99
          $ref: "../swagger.yaml#/definitions/error"
100
      "403":
100
      "403":
101
        description: Cannot create checkout
101
        description: Cannot create checkout
Lines 370-372 Link Here
370
    x-koha-authorization:
370
    x-koha-authorization:
371
      permissions:
371
      permissions:
372
        circulate: circulate_remaining_permissions
372
        circulate: circulate_remaining_permissions
373
"/public/checkouts/availability":
374
  get:
375
    x-mojo-to: Checkouts#get_availability
376
    operationId: availabilityCheckoutsPublic
377
    tags:
378
      - checkouts
379
    summary: Get checkout availability
380
    parameters:
381
      - $ref: "../swagger.yaml#/parameters/patron_id_qp"
382
      - $ref: "../swagger.yaml#/parameters/item_id_qp"
383
    produces:
384
      - application/json
385
    responses:
386
      "200":
387
        description: Availability
388
        schema:
389
          type: "object"
390
      "403":
391
        description: Access forbidden
392
        schema:
393
          $ref: "../swagger.yaml#/definitions/error"
394
      "500":
395
        description: |
396
          Internal server error. Possible `error_code` attribute values:
397
398
          * `internal_server_error`
399
        schema:
400
          $ref: "../swagger.yaml#/definitions/error"
401
      "503":
402
        description: Under maintenance
403
        schema:
404
          $ref: "../swagger.yaml#/definitions/error"
(-)a/api/v1/swagger/paths/public_patrons.yaml (+60 lines)
Lines 62-67 Link Here
62
          $ref: "../swagger.yaml#/definitions/error"
62
          $ref: "../swagger.yaml#/definitions/error"
63
    x-koha-authorization:
63
    x-koha-authorization:
64
      allow-owner: true
64
      allow-owner: true
65
"/public/patrons/{patron_id}/checkouts":
66
  post:
67
    x-mojo-to: Checkouts#add
68
    operationId: addCheckoutPublic
69
    tags:
70
      - checkouts
71
      - patrons
72
    summary: Add a new checkout
73
    parameters:
74
      - name: body
75
        in: body
76
        description: A JSON object containing information about the new checkout
77
        required: true
78
        schema:
79
          $ref: "../swagger.yaml#/definitions/checkout"
80
      - name: confirmation
81
        in: query
82
        description: A JWT confirmation token
83
        required: false
84
        type: string
85
    produces:
86
      - application/json
87
    responses:
88
      "201":
89
        description: Created checkout
90
        schema:
91
          $ref: "../swagger.yaml#/definitions/checkout"
92
      "400":
93
        description: Missing or wrong parameters
94
        schema:
95
          $ref: "../swagger.yaml#/definitions/error"
96
      "401":
97
        description: Authentication required
98
        schema:
99
          $ref: "../swagger.yaml#/definitions/error"
100
      "403":
101
        description: Cannot create checkout
102
        schema:
103
          $ref: "../swagger.yaml#/definitions/error"
104
      "409":
105
        description: Conflict in creating checkout
106
        schema:
107
          $ref: "../swagger.yaml#/definitions/error"
108
      "412":
109
        description: Precondition failed
110
        schema:
111
          $ref: "../swagger.yaml#/definitions/error"
112
      "500":
113
        description: |
114
          Internal server error. Possible `error_code` attribute values:
115
116
          * `internal_server_error`
117
        schema:
118
          $ref: "../swagger.yaml#/definitions/error"
119
      "503":
120
        description: Under maintenance
121
        schema:
122
          $ref: "../swagger.yaml#/definitions/error"
123
    x-koha-authorization:
124
      allow-owner: true
65
"/public/patrons/{patron_id}/guarantors/can_see_charges":
125
"/public/patrons/{patron_id}/guarantors/can_see_charges":
66
  put:
126
  put:
67
    x-mojo-to: Patrons#guarantors_can_see_charges
127
    x-mojo-to: Patrons#guarantors_can_see_charges
(-)a/api/v1/swagger/swagger.yaml (-1 / +4 lines)
Lines 307-312 paths: Link Here
307
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
307
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
308
  "/public/biblios/{biblio_id}":
308
  "/public/biblios/{biblio_id}":
309
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
309
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
310
  "/public/checkouts/availability":
311
    $ref: ./paths/checkouts.yaml#/~1public~1checkouts~1availability
310
  "/public/items":
312
  "/public/items":
311
    $ref: "./paths/items.yaml#/~1public~1items"
313
    $ref: "./paths/items.yaml#/~1public~1items"
312
  "/public/biblios/{biblio_id}/items":
314
  "/public/biblios/{biblio_id}/items":
Lines 321-326 paths: Link Here
321
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
323
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
322
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
324
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
323
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
325
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
326
  "/public/patrons/{patron_id}/checkouts":
327
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1checkouts"
324
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
328
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
325
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_charges"
329
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_charges"
326
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts":
330
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts":
327
- 

Return to bug 30979