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

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

Return to bug 17003