Lines 18-23
package Koha::REST::V1::Checkouts;
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
|
|
21 |
use Mojo::JSON; |
21 |
|
22 |
|
22 |
use C4::Auth qw( haspermission ); |
23 |
use C4::Auth qw( haspermission ); |
23 |
use C4::Context; |
24 |
use C4::Context; |
Lines 127-132
sub renew {
Link Here
|
127 |
); |
128 |
); |
128 |
} |
129 |
} |
129 |
|
130 |
|
|
|
131 |
sub renewability { |
132 |
my ($c, $args, $cb) = @_; |
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 |
|
146 |
my $checkout_id = $args->{checkout_id}; |
147 |
my $checkout = Koha::Issues->find($checkout_id); |
148 |
|
149 |
if (!$checkout) { |
150 |
return $c->$cb({ |
151 |
error => "Checkout doesn't exist" |
152 |
}, 404); |
153 |
} |
154 |
|
155 |
my $borrowernumber = $checkout->borrowernumber; |
156 |
my $itemnumber = $checkout->itemnumber; |
157 |
|
158 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
159 |
$borrowernumber, $itemnumber); |
160 |
|
161 |
return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew; |
162 |
return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200); |
163 |
} |
164 |
|
130 |
=head3 _to_api |
165 |
=head3 _to_api |
131 |
|
166 |
|
132 |
Helper function that maps a hashref of Koha::Checkout attributes into REST api |
167 |
Helper function that maps a hashref of Koha::Checkout attributes into REST api |