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

(-)a/Koha/REST/V1/Checkouts.pm (-23 / +49 lines)
Lines 100-105 sub get { Link Here
100
    };
100
    };
101
}
101
}
102
102
103
=head3 _check_availability 
104
105
Internal function to call CanBookBeIssued and return an appropriately filtered 
106
set return
107
108
=cut
109
110
sub _check_availability {
111
    my ( $c, $patron, $item ) = @_;
112
113
    my $inprocess       = 0;                   # What does this do?
114
    my $ignore_reserves = 0;                   # Don't ignore reserves
115
    my $params          = { item => $item };
116
117
    my ( $impossible, $confirmation, $alerts, $messages ) =
118
      C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess,
119
        $ignore_reserves, $params );
120
121
    if ( $c->stash('is_public') ) {
122
123
        # Upgrade some confirmations to blockers
124
        my @should_block =
125
          qw/TOO_MANY ISSUED_TO_ANOTHER RESERVED RESERVED_WAITING TRANSFERRED PROCESSING AGE_RESTRICTION/;
126
        for my $block (@should_block) {
127
            if ( exists( $confirmation->{$block} ) ) {
128
                $impossible->{$block} = $confirmation->{$block};
129
                delete $confirmation->{$block};
130
            }
131
        }
132
133
        # Remove any non-public info that's returned by CanBookBeIssued
134
        my @restricted_keys =
135
          qw/issued_borrowernumber issued_cardnumber issued_firstname issued_surname resborrowernumber resbranchcode rescardnumber reserve_id resfirstname resreservedate ressurname item_notforloan/;
136
        for my $key (@restricted_keys) {
137
            delete $confirmation->{$key};
138
            delete $impossible->{$key};
139
            delete $alerts->{$key};
140
            delete $messages->{$key};
141
        }
142
    }
143
144
    return ( $impossible, $confirmation, { %{$alerts}, %{$messages} } );
145
}
146
103
=head3 get_availability
147
=head3 get_availability
104
148
105
Controller function that handles retrieval of Checkout availability
149
Controller function that handles retrieval of Checkout availability
Lines 111-126 sub get_availability { Link Here
111
    my $user = $c->stash('koha.user');
155
    my $user = $c->stash('koha.user');
112
156
113
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
157
    my $patron = Koha::Patrons->find( $c->param('patron_id') );
114
    my $inprocess = 0; # What does this do?
115
    my $ignore_reserves = 0; # Don't ignore reserves
116
    my $item   = Koha::Items->find( $c->param('item_id') );
158
    my $item   = Koha::Items->find( $c->param('item_id') );
117
    my $params = {
118
        item => $item
119
    };
120
159
121
    my ( $impossible, $confirmation, $alerts, $messages ) =
160
    my ( $impossible, $confirmation, $warnings ) =
122
      C4::Circulation::CanBookBeIssued( $patron, undef, undef, $inprocess, $ignore_reserves,
161
      $c->_check_availability( $patron, $item );
123
        $params );
124
162
125
    my $confirm_keys = join( ":", sort keys %{$confirmation} );
163
    my $confirm_keys = join( ":", sort keys %{$confirmation} );
126
    $confirm_keys = $user->id . ":" . $item->id . ":" . $confirm_keys;
164
    $confirm_keys = $user->id . ":" . $item->id . ":" . $confirm_keys;
Lines 129-135 sub get_availability { Link Here
129
    my $response = {
167
    my $response = {
130
        blockers           => $impossible,
168
        blockers           => $impossible,
131
        confirms           => $confirmation,
169
        confirms           => $confirmation,
132
        warnings           => { %{$alerts}, %{$messages} },
170
        warnings           => $warnings,
133
        confirmation_token => $token
171
        confirmation_token => $token
134
    };
172
    };
135
173
Lines 174-193 sub add { Link Here
174
            );
212
            );
175
        }
213
        }
176
214
177
        my $inprocess       = 0;                   # What does this do?
215
        my ( $impossible, $confirmation, $warnings ) =
178
        my $ignore_reserves = 0;                   # Don't ignore reserves
216
          $c->_check_availability( $patron, $item );
179
        my $params          = { item => $item };
180
181
        # Call 'CanBookBeIssued'
182
        my ( $impossible, $confirmation, $alerts, $messages ) =
183
          C4::Circulation::CanBookBeIssued(
184
             $patron,
185
             undef,
186
             undef,
187
             $inprocess,
188
             $ignore_reserves,
189
             $params
190
        );
191
217
192
        # * Fail for blockers - render 403
218
        # * Fail for blockers - render 403
193
        if ( keys %{$impossible} ) {
219
        if ( keys %{$impossible} ) {
(-)a/api/v1/swagger/paths/checkouts.yaml (-4 / +36 lines)
Lines 88-100 Link Here
88
        description: Created checkout
88
        description: Created checkout
89
        schema:
89
        schema:
90
          $ref: "../swagger.yaml#/definitions/checkout"
90
          $ref: "../swagger.yaml#/definitions/checkout"
91
      "400":
91
      "400": 
92
        description: Missing or wrong parameters
92
        description: Missing or wrong parameters
93
        schema:
93
        schema: 
94
          $ref: "../swagger.yaml#/definitions/error"
94
          $ref: "../swagger.yaml#/definitions/error"
95
      "401":
95
      "401": 
96
        description: Authentication required
96
        description: Authentication required
97
        schema:
97
        schema: 
98
          $ref: "../swagger.yaml#/definitions/error"
98
          $ref: "../swagger.yaml#/definitions/error"
99
      "403":
99
      "403":
100
        description: Cannot create checkout
100
        description: Cannot create checkout
Lines 369-371 Link Here
369
    x-koha-authorization:
369
    x-koha-authorization:
370
      permissions:
370
      permissions:
371
        circulate: circulate_remaining_permissions
371
        circulate: circulate_remaining_permissions
372
"/public/checkouts/availability":
373
  get:
374
    x-mojo-to: Checkouts#get_availability
375
    operationId: availabilityCheckoutsPublic
376
    tags:
377
      - checkouts
378
    summary: Get checkout availability
379
    parameters:
380
      - $ref: "../swagger.yaml#/parameters/patron_id_qp"
381
      - $ref: "../swagger.yaml#/parameters/item_id_qp"
382
    produces:
383
      - application/json
384
    responses:
385
      "200":
386
        description: Availability
387
        schema:
388
          type: "object"
389
      "403":
390
        description: Access forbidden
391
        schema:
392
          $ref: "../swagger.yaml#/definitions/error"
393
      "500":
394
        description: |
395
          Internal server error. Possible `error_code` attribute values:
396
397
          * `internal_server_error`
398
        schema:
399
          $ref: "../swagger.yaml#/definitions/error"
400
      "503":
401
        description: Under maintenance
402
        schema:
403
          $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 315-320 paths: Link Here
315
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
315
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
316
  "/public/biblios/{biblio_id}":
316
  "/public/biblios/{biblio_id}":
317
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
317
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
318
  "/public/checkouts/availability":
319
    $ref: ./paths/checkouts.yaml#/~1public~1checkouts~1availability
318
  "/public/items":
320
  "/public/items":
319
    $ref: "./paths/items.yaml#/~1public~1items"
321
    $ref: "./paths/items.yaml#/~1public~1items"
320
  "/public/biblios/{biblio_id}/items":
322
  "/public/biblios/{biblio_id}/items":
Lines 329-334 paths: Link Here
329
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
331
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
330
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
332
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
331
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
333
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
334
  "/public/patrons/{patron_id}/checkouts":
335
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1checkouts"
332
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
336
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
333
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_charges"
337
    $ref: "./paths/public_patrons.yaml#/~1public~1patrons~1{patron_id}~1guarantors~1can_see_charges"
334
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts":
338
  "/public/patrons/{patron_id}/guarantors/can_see_checkouts":
335
- 

Return to bug 30979