Lines 18-26
package Koha::REST::V1::Acquisitions::Baskets;
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 |
|
|
|
22 |
use Try::Tiny qw( catch try ); |
21 |
use Try::Tiny qw( catch try ); |
23 |
|
22 |
|
|
|
23 |
use C4::Acquisition qw( CanUserManageBasket ); |
24 |
|
24 |
=head1 NAME |
25 |
=head1 NAME |
25 |
|
26 |
|
26 |
Koha::REST::V1::Acquisitions::Baskets |
27 |
Koha::REST::V1::Acquisitions::Baskets |
Lines 65-77
Return a list of baskets
Link Here
|
65 |
=cut |
66 |
=cut |
66 |
|
67 |
|
67 |
sub list { |
68 |
sub list { |
68 |
my $c = shift->openapi->valid_input or return; |
69 |
my $c = shift->openapi->valid_input or return; |
|
|
70 |
my $patron = $c->stash('koha.user'); |
69 |
|
71 |
|
70 |
return try { |
72 |
return try { |
71 |
|
73 |
|
|
|
74 |
my $baskets_rs = Koha::Acquisition::Baskets->new; |
75 |
my $baskets = $c->objects->search($baskets_rs); |
76 |
|
77 |
my $userflags = C4::Auth::getuserflags( $patron->flags, $patron->userid ); |
78 |
|
79 |
my @user_baskets; |
80 |
foreach my $basket (@$baskets) { |
81 |
my $success = CanUserManageBasket( $patron->unblessed, $basket, $userflags ); |
82 |
push @user_baskets, $basket if $success; |
83 |
} |
84 |
|
72 |
return $c->render( |
85 |
return $c->render( |
73 |
status => 200, |
86 |
status => 200, |
74 |
openapi => $c->objects->search( Koha::Acquisition::Baskets->new ), |
87 |
openapi => \@user_baskets |
75 |
); |
88 |
); |
76 |
} catch { |
89 |
} catch { |
77 |
$c->unhandled_exception($_); |
90 |
$c->unhandled_exception($_); |