Lines 4-14
use Modern::Perl;
Link Here
|
4 |
|
4 |
|
5 |
use Mojo::Base 'Mojolicious::Controller'; |
5 |
use Mojo::Base 'Mojolicious::Controller'; |
6 |
|
6 |
|
|
|
7 |
use C4::Auth qw( haspermission ); |
7 |
use Koha::Borrowers; |
8 |
use Koha::Borrowers; |
8 |
|
9 |
|
9 |
sub list_borrowers { |
10 |
sub list_borrowers { |
10 |
my ($c, $args, $cb) = @_; |
11 |
my ($c, $args, $cb) = @_; |
11 |
|
12 |
|
|
|
13 |
my $user = $c->stash('koha.user'); |
14 |
unless ($user && haspermission($user->userid, {borrowers => 1})) { |
15 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
16 |
} |
17 |
|
12 |
my $borrowers = Koha::Borrowers->search; |
18 |
my $borrowers = Koha::Borrowers->search; |
13 |
|
19 |
|
14 |
$c->$cb($borrowers->unblessed, 200); |
20 |
$c->$cb($borrowers->unblessed, 200); |
Lines 17-29
sub list_borrowers {
Link Here
|
17 |
sub get_borrower { |
23 |
sub get_borrower { |
18 |
my ($c, $args, $cb) = @_; |
24 |
my ($c, $args, $cb) = @_; |
19 |
|
25 |
|
20 |
my $borrower = Koha::Borrowers->find($args->{borrowernumber}); |
26 |
my $user = $c->stash('koha.user'); |
21 |
|
27 |
|
22 |
if ($borrower) { |
28 |
unless ( $user |
23 |
return $c->$cb($borrower->unblessed, 200); |
29 |
&& ( $user->borrowernumber == $args->{borrowernumber} |
|
|
30 |
|| haspermission($user->userid, {borrowers => 1}) ) ) |
31 |
{ |
32 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
33 |
} |
34 |
|
35 |
my $borrower = Koha::Borrowers->find($args->{borrowernumber}); |
36 |
unless ($borrower) { |
37 |
return $c->$cb({error => "Borrower not found"}, 404); |
24 |
} |
38 |
} |
25 |
|
39 |
|
26 |
$c->$cb({error => "Borrower not found"}, 404); |
40 |
return $c->$cb($borrower->unblessed, 200); |
27 |
} |
41 |
} |
28 |
|
42 |
|
29 |
1; |
43 |
1; |