View | Details | Raw Unified | Return to bug 27358
Collapse All | Expand All

(-)a/Koha/Item.pm (-17 / +31 lines)
Lines 1104-1109 sub _set_found_trigger { Link Here
1104
    return $self;
1104
    return $self;
1105
}
1105
}
1106
1106
1107
=head3 public_read_list
1108
1109
This method returns the list of publically readable database fields for both API and UI output purposes
1110
1111
=cut
1112
1113
sub public_read_list {
1114
    return [
1115
        'itemnumber',         'biblionumber',
1116
        'biblioitemnumber',   'barcode',
1117
        'dateaccessioned',    'booksellerid',
1118
        'homebranch',         'price',
1119
        'replacementprice',   'replacementpricedate',
1120
        'datelastborrowed',   'datelastseen',
1121
        'stack',              'notforloan',
1122
        'damaged',            'damaged_on',
1123
        'itemlost',           'itemlost_on',
1124
        'withdrawn',          'withdrawn_on',
1125
        'itemcallnumber',     'coded_location_qualifier',
1126
        'renewals',           'restricted',
1127
        'itemnotes',          'holdingbranch',
1128
        'timestamp',          'location',
1129
        'permanent_location', 'cn_source',
1130
        'cn_sort',            'ccode',
1131
        'materials',          'uri',
1132
        'itype',              'enumchron',
1133
        'copynumber',         'stocknumber',
1134
        'new_status'
1135
    ];
1136
}
1137
1107
=head3 to_api_mapping
1138
=head3 to_api_mapping
1108
1139
1109
This method returns the mapping for representing a Koha::Item object
1140
This method returns the mapping for representing a Koha::Item object
Lines 1160-1182 sub to_api_mapping { Link Here
1160
    };
1191
    };
1161
}
1192
}
1162
1193
1163
=head3 api_privileged_attrs
1164
1165
This method returns the list of privileged access-only attributes. This is used
1166
by $item->to_api($params) to render the object correctly, based on the passed I<$params>.
1167
1168
=cut
1169
1170
sub api_privileged_attrs {
1171
    return [
1172
        'checked_out_date',
1173
        'checkouts_count',
1174
        'holds_count',
1175
        'internal_notes',
1176
        'extended_subfields',
1177
    ];
1178
}
1179
1180
=head3 itemtype
1194
=head3 itemtype
1181
1195
1182
    my $itemtype = $item->itemtype;
1196
    my $itemtype = $item->itemtype;
(-)a/Koha/Object.pm (-10 / +11 lines)
Lines 24-29 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
28
28
use Koha::Database;
29
use Koha::Database;
29
use Koha::Exceptions::Object;
30
use Koha::Exceptions::Object;
Lines 552-557 sub to_api { Link Here
552
    my ( $self, $params ) = @_;
553
    my ( $self, $params ) = @_;
553
    my $json_object = $self->TO_JSON;
554
    my $json_object = $self->TO_JSON;
554
555
556
    # Remove forbidden attributes if required
557
    # FIXME: We should eventually require public_read_list in all objects and drop the conditional here.
558
    if (    $params->{public}
559
        and $self->can('public_read_list') )
560
    {
561
        for my $field ( keys %{$json_object} ) {
562
            delete $json_object->{$field} unless any { $_ eq $field } $self->public_read_list;
563
        }
564
    }
565
555
    my $to_api_mapping = $self->to_api_mapping;
566
    my $to_api_mapping = $self->to_api_mapping;
556
567
557
    # Rename attributes if there's a mapping
568
    # Rename attributes if there's a mapping
Lines 573-587 sub to_api { Link Here
573
        }
584
        }
574
    }
585
    }
575
586
576
    # Remove forbidden attributes if required
577
    if (    $params->{public}
578
        and $self->can('api_privileged_attrs') )
579
    {
580
        foreach my $privileged_attr ( @{ $self->api_privileged_attrs } ) {
581
            delete $json_object->{$privileged_attr};
582
        }
583
    }
584
585
    # Make sure we duplicate the $params variable to avoid
587
    # Make sure we duplicate the $params variable to avoid
586
    # breaking calls in a loop (Koha::Objects->to_api)
588
    # breaking calls in a loop (Koha::Objects->to_api)
587
    $params    = {%$params};
589
    $params    = {%$params};
588
- 

Return to bug 27358