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

(-)a/Koha/REST/V1/Checkouts.pm (-25 / +15 lines)
Lines 129-165 sub renew { Link Here
129
}
129
}
130
130
131
sub renewability {
131
sub renewability {
132
    my ($c, $args, $cb) = @_;
132
    my $c = shift->openapi->valid_input or return;
133
134
    my $user = $c->stash('koha.user');
135
136
    my $OpacRenewalAllowed;
137
    if ($user->borrowernumber == $borrowernumber) {
138
        $OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed');
139
    }
140
141
    unless ($user && ($OpacRenewalAllowed
142
            || haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) {
143
        return $c->$cb({error => "You don't have the required permission"}, 403);
144
    }
145
133
146
    my $checkout_id = $args->{checkout_id};
134
    my $checkout_id = $c->validation->param('checkout_id');
147
    my $checkout = Koha::Issues->find($checkout_id);
135
    my $checkout = Koha::Checkouts->find( $checkout_id );
148
136
149
    if (!$checkout) {
137
    unless ($checkout) {
150
        return $c->$cb({
138
        return $c->render(
151
            error => "Checkout doesn't exist"
139
            status => 404,
152
        }, 404);
140
            openapi => { error => "Checkout doesn't exist" }
141
        );
153
    }
142
    }
154
143
155
    my $borrowernumber = $checkout->borrowernumber;
156
    my $itemnumber = $checkout->itemnumber;
157
158
    my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
144
    my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
159
        $borrowernumber, $itemnumber);
145
        $checkout->borrowernumber, $checkout->itemnumber);
160
146
161
    return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew;
147
    my $renewable = Mojo::JSON->false;
162
    return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200);
148
    $renewable = Mojo::JSON->true if $can_renew;
149
    return $c->render(
150
        status => 200,
151
        openapi => { renewable => $renewable, error => $error }
152
    );
163
}
153
}
164
154
165
=head3 _to_api
155
=head3 _to_api
(-)a/api/v1/swagger/paths/checkouts.json (-2 / +1 lines)
Lines 99-104 Link Here
99
  },
99
  },
100
  "/checkouts/{checkout_id}/renewability": {
100
  "/checkouts/{checkout_id}/renewability": {
101
    "get": {
101
    "get": {
102
      "x-mojo-to": "Checkout#renewability",
102
      "operationId": "renewabilityCheckout",
103
      "operationId": "renewabilityCheckout",
103
      "tags": ["patrons", "checkouts"],
104
      "tags": ["patrons", "checkouts"],
104
      "parameters": [{
105
      "parameters": [{
Lines 120-127 Link Here
120
        }
121
        }
121
      },
122
      },
122
      "x-koha-authorization": {
123
      "x-koha-authorization": {
123
        "allow-owner": true,
124
        "allow-guarantor": true,
125
        "permissions": {
124
        "permissions": {
126
          "circulate": "circulate_remaining_permissions"
125
          "circulate": "circulate_remaining_permissions"
127
        }
126
        }
(-)a/t/db_dependent/api/v1/checkouts.t (-7 / +2 lines)
Lines 169-177 $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i Link Here
169
              required_permissions => { circulate => "circulate_remaining_permissions" }
169
              required_permissions => { circulate => "circulate_remaining_permissions" }
170
            });
170
            });
171
171
172
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/" . $issue2->issue_id . "/renewability");
172
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
173
$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id});
174
$t->request_ok($tx)
175
  ->status_is(200)
173
  ->status_is(200)
176
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
174
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
177
175
Lines 185-192 $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/re Link Here
185
  ->status_is(403)
183
  ->status_is(403)
186
  ->json_is({ error => 'Renewal not authorized (too_many)' });
184
  ->json_is({ error => 'Renewal not authorized (too_many)' });
187
185
188
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/" . $issue2->issue_id . "/renewability");
186
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
189
$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id});
190
$t->request_ok($tx)
191
  ->status_is(200)
187
  ->status_is(200)
192
  ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' });
188
  ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' });
193
- 

Return to bug 17003