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

(-)a/Koha/REST/V1/Checkout.pm (-25 / +15 lines)
Lines 126-162 sub renew { Link Here
126
}
126
}
127
127
128
sub renewability {
128
sub renewability {
129
    my ($c, $args, $cb) = @_;
129
    my $c = shift->openapi->valid_input or return;
130
131
    my $user = $c->stash('koha.user');
132
133
    my $OpacRenewalAllowed;
134
    if ($user->borrowernumber == $borrowernumber) {
135
        $OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed');
136
    }
137
138
    unless ($user && ($OpacRenewalAllowed
139
            || haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) {
140
        return $c->$cb({error => "You don't have the required permission"}, 403);
141
    }
142
130
143
    my $checkout_id = $args->{checkout_id};
131
    my $checkout_id = $c->validation->param('checkout_id');
144
    my $checkout = Koha::Issues->find($checkout_id);
132
    my $checkout = Koha::Checkouts->find( $checkout_id );
145
133
146
    if (!$checkout) {
134
    unless ($checkout) {
147
        return $c->$cb({
135
        return $c->render(
148
            error => "Checkout doesn't exist"
136
            status => 404,
149
        }, 404);
137
            openapi => { error => "Checkout doesn't exist" }
138
        );
150
    }
139
    }
151
140
152
    my $borrowernumber = $checkout->borrowernumber;
153
    my $itemnumber = $checkout->itemnumber;
154
155
    my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
141
    my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
156
        $borrowernumber, $itemnumber);
142
        $checkout->borrowernumber, $checkout->itemnumber);
157
143
158
    return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew;
144
    my $renewable = Mojo::JSON->false;
159
    return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200);
145
    $renewable = Mojo::JSON->true if $can_renew;
146
    return $c->render(
147
        status => 200,
148
        openapi => { renewable => $renewable, error => $error }
149
    );
160
}
150
}
161
151
162
=head3 _to_api
152
=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 146-154 $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i Link Here
146
              required_permissions => { circulate => "circulate_remaining_permissions" }
146
              required_permissions => { circulate => "circulate_remaining_permissions" }
147
            });
147
            });
148
148
149
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/" . $issue2->issue_id . "/renewability");
149
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability")
150
$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id});
151
$t->request_ok($tx)
152
  ->status_is(200)
150
  ->status_is(200)
153
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
151
  ->json_is({ renewable => Mojo::JSON->true, error => undef });
154
152
Lines 160-168 $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
164
169
- 

Return to bug 17003