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 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