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