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

(-)a/Koha/REST/V1/Checkouts.pm (-24 / +50 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 113-128 sub get_availability { Link Here
113
    my $user = $c->stash('koha.user');
157
    my $user = $c->stash('koha.user');
114
158
115
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
159
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
116
    my $inprocess = 0; # What does this do?
117
    my $ignore_reserves = 0; # Don't ignore reserves
118
    my $item   = Koha::Items->find( $c->param('item_id') );
160
    my $item   = Koha::Items->find( $c->param('item_id') );
119
    my $params = {
120
        item => $item
121
    };
122
161
123
    my ( $impossible, $confirmation, $alerts, $messages ) =
162
    my ( $impossible, $confirmation, $warnings ) =
124
      C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves,
163
      $c->_check_availability( $patron, $item );
125
        $params );
126
164
127
    my $confirm_keys = join( ":", sort keys %{$confirmation} );
165
    my $confirm_keys = join( ":", sort keys %{$confirmation} );
128
    $confirm_keys = $user->id . ":" . $item->id . ":" . $confirm_keys;
166
    $confirm_keys = $user->id . ":" . $item->id . ":" . $confirm_keys;
Lines 131-137 sub get_availability { Link Here
131
    my $response = {
169
    my $response = {
132
        blockers           => $impossible,
170
        blockers           => $impossible,
133
        confirms           => $confirmation,
171
        confirms           => $confirmation,
134
        warnings           => { %{$alerts}, %{$messages} },
172
        warnings           => $warnings,
135
        confirmation_token => $token
173
        confirmation_token => $token
136
    };
174
    };
137
175
Lines 176-195 sub add { Link Here
176
            );
214
            );
177
        }
215
        }
178
216
179
        my $inprocess       = 0;                   # What does this do?
217
        my ( $impossible, $confirmation, $warnings ) =
180
        my $ignore_reserves = 0;                   # Don't ignore reserves
218
          $c->_check_availability( $patron, $item );
181
        my $params          = { item => $item };
182
183
        # Call 'CanBookBeIssued'
184
        my ( $impossible, $confirmation, $alerts, $messages ) =
185
          C4::Circulation::CanBookBeIssued(
186
             $patron,
187
             undef,
188
             undef,
189
             $inprocess,
190
             $ignore_reserves,
191
             $params
192
        );
193
219
194
        # * Fail for blockers - render 403
220
        # * Fail for blockers - render 403
195
        if ( keys %{$impossible} ) {
221
        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 (+61 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
      - $ref: "../swagger.yaml#/parameters/patron_id_pp"
75
      - name: body
76
        in: body
77
        description: A JSON object containing information about the new checkout
78
        required: true
79
        schema:
80
          $ref: "../swagger.yaml#/definitions/checkout"
81
      - name: confirmation
82
        in: query
83
        description: A JWT confirmation token
84
        required: false
85
        type: string
86
    produces:
87
      - application/json
88
    responses:
89
      "201":
90
        description: Created checkout
91
        schema:
92
          $ref: "../swagger.yaml#/definitions/checkout"
93
      "400":
94
        description: Missing or wrong parameters
95
        schema:
96
          $ref: "../swagger.yaml#/definitions/error"
97
      "401":
98
        description: Authentication required
99
        schema:
100
          $ref: "../swagger.yaml#/definitions/error"
101
      "403":
102
        description: Cannot create checkout
103
        schema:
104
          $ref: "../swagger.yaml#/definitions/error"
105
      "409":
106
        description: Conflict in creating checkout
107
        schema:
108
          $ref: "../swagger.yaml#/definitions/error"
109
      "412":
110
        description: Precondition failed
111
        schema:
112
          $ref: "../swagger.yaml#/definitions/error"
113
      "500":
114
        description: |
115
          Internal server error. Possible `error_code` attribute values:
116
117
          * `internal_server_error`
118
        schema:
119
          $ref: "../swagger.yaml#/definitions/error"
120
      "503":
121
        description: Under maintenance
122
        schema:
123
          $ref: "../swagger.yaml#/definitions/error"
124
    x-koha-authorization:
125
      allow-owner: true
65
"/public/patrons/{patron_id}/guarantors/can_see_charges":
126
"/public/patrons/{patron_id}/guarantors/can_see_charges":
66
  put:
127
  put:
67
    x-mojo-to: Patrons#guarantors_can_see_charges
128
    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