Lines 18-23
package Koha::REST::V1::Checkout;
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 105-108
sub renew {
Link Here
|
105 |
return $c->$cb($checkout->unblessed, 200); |
106 |
return $c->$cb($checkout->unblessed, 200); |
106 |
} |
107 |
} |
107 |
|
108 |
|
|
|
109 |
sub renewability { |
110 |
my ($c, $args, $cb) = @_; |
111 |
|
112 |
my $user = $c->stash('koha.user'); |
113 |
|
114 |
my $checkout_id = $args->{checkout_id}; |
115 |
my $checkout = Koha::Issues->find($checkout_id); |
116 |
|
117 |
if (!$checkout) { |
118 |
return $c->$cb({ |
119 |
error => "Checkout doesn't exist" |
120 |
}, 404); |
121 |
} |
122 |
|
123 |
my $borrowernumber = $checkout->borrowernumber; |
124 |
my $itemnumber = $checkout->itemnumber; |
125 |
|
126 |
my $OpacRenewalAllowed; |
127 |
if ($user->borrowernumber == $borrowernumber) { |
128 |
$OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed'); |
129 |
} |
130 |
|
131 |
unless ($user && ($OpacRenewalAllowed |
132 |
|| haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) { |
133 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
134 |
} |
135 |
|
136 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
137 |
$borrowernumber, $itemnumber); |
138 |
|
139 |
return $c->$cb({}, 200) if $can_renew; |
140 |
return $c->$cb({error => "Renewal not authorized ($error)"}, 403); |
141 |
} |
142 |
|
108 |
1; |
143 |
1; |