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 86-89
sub renew {
Link Here
|
86 |
return $c->$cb($checkout->unblessed, 200); |
87 |
return $c->$cb($checkout->unblessed, 200); |
87 |
} |
88 |
} |
88 |
|
89 |
|
|
|
90 |
sub renewability { |
91 |
my ($c, $args, $cb) = @_; |
92 |
|
93 |
my $user = $c->stash('koha.user'); |
94 |
|
95 |
my $checkout_id = $args->{checkout_id}; |
96 |
my $checkout = Koha::Issues->find($checkout_id); |
97 |
|
98 |
if (!$checkout) { |
99 |
return $c->$cb({ |
100 |
error => "Checkout doesn't exist" |
101 |
}, 404); |
102 |
} |
103 |
|
104 |
my $borrowernumber = $checkout->borrowernumber; |
105 |
my $itemnumber = $checkout->itemnumber; |
106 |
|
107 |
my $OpacRenewalAllowed; |
108 |
if ($user->borrowernumber == $borrowernumber) { |
109 |
$OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed'); |
110 |
} |
111 |
|
112 |
unless ($user && ($OpacRenewalAllowed |
113 |
|| haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) { |
114 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
115 |
} |
116 |
|
117 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
118 |
$borrowernumber, $itemnumber); |
119 |
|
120 |
return $c->$cb({}, 200) if $can_renew; |
121 |
return $c->$cb({error => "Renewal not authorized ($error)"}, 403); |
122 |
} |
123 |
|
89 |
1; |
124 |
1; |