Lines 24-30
use Carp qw( croak );
Link Here
|
24 |
use Mojo::JSON; |
24 |
use Mojo::JSON; |
25 |
use Scalar::Util qw( blessed looks_like_number ); |
25 |
use Scalar::Util qw( blessed looks_like_number ); |
26 |
use Try::Tiny qw( catch try ); |
26 |
use Try::Tiny qw( catch try ); |
27 |
use List::MoreUtils qw( any ); |
27 |
use Module::Load::Conditional qw( can_load ); |
28 |
|
28 |
|
29 |
use Koha::Database; |
29 |
use Koha::Database; |
30 |
use Koha::Exceptions::Object; |
30 |
use Koha::Exceptions::Object; |
Lines 552-566
Returns a representation of the object, suitable for API output.
Link Here
|
552 |
sub to_api { |
552 |
sub to_api { |
553 |
my ( $self, $params ) = @_; |
553 |
my ( $self, $params ) = @_; |
554 |
my $json_object = $self->TO_JSON; |
554 |
my $json_object = $self->TO_JSON; |
|
|
555 |
$params //= {}; |
555 |
|
556 |
|
556 |
# Remove forbidden attributes if required |
557 |
# Remove forbidden attributes if required |
557 |
# FIXME: We should eventually require public_read_list in all objects and drop the conditional here. |
558 |
# FIXME: All modules should have a corresponding allowlist eventually |
558 |
if ( $params->{public} |
559 |
my $allowclass = ref($self) . '::Allowlist'; |
559 |
and $self->can('public_read_list') ) |
560 |
if ( can_load( modules => { $allowclass => undef } ) ) { |
560 |
{ |
561 |
my $allowlist = $allowclass->new( |
561 |
for my $field ( keys %{$json_object} ) { |
562 |
{ interface => $params->{public} ? 'opac' : 'staff' } ); |
562 |
delete $json_object->{$field} unless any { $_ eq $field } @{$self->public_read_list}; |
563 |
$allowlist->load; |
563 |
} |
564 |
my $blocked = $allowlist->apply( { input => $json_object } ); |
|
|
565 |
Koha::Logger->get->debug( |
566 |
ref($self) |
567 |
. "::to_api allowlist blocked fields: " |
568 |
. ( |
569 |
join ', ', |
570 |
map { $_ . '=' . $blocked->{$_} } sort keys %$blocked |
571 |
) |
572 |
) if keys %$blocked; |
564 |
} |
573 |
} |
565 |
|
574 |
|
566 |
my $to_api_mapping = $self->to_api_mapping; |
575 |
my $to_api_mapping = $self->to_api_mapping; |