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

(-)a/Koha/Checkout.pm (+15 lines)
Lines 237-242 sub to_api_mapping { Link Here
237
    };
237
    };
238
}
238
}
239
239
240
=head3 public_read_list
241
242
This method returns the list of publicly readable database fields for both API and UI output purposes
243
244
=cut
245
246
sub public_read_list {
247
    return [
248
        'checkin_library', 'issue_id',        'borrowernumber',
249
        'itemnumber',      'date_due',        'branchcode',
250
        'returndate',      'lastreneweddate', 'issuedate',
251
        'notedate',        'noteseen'
252
    ];
253
}
254
240
=head3 claim_returned
255
=head3 claim_returned
241
256
242
  my $return_claim = $checkout->claim_returned();
257
  my $return_claim = $checkout->claim_returned();
(-)a/t/db_dependent/Koha/Checkout.t (-2 / +51 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
24
25
use Koha::Database;
25
use Koha::Database;
Lines 136-138 subtest 'renewals() tests' => sub { Link Here
136
136
137
    $schema->storage->txn_rollback;
137
    $schema->storage->txn_rollback;
138
};
138
};
139
- 
139
140
subtest 'public_read_list() tests' => sub {
141
142
    $schema->storage->txn_begin;
143
144
    my @all_attrs = Koha::Checkouts->columns();
145
    my $public_attrs =
146
        { map { $_ => 1 } @{ Koha::Checkout->public_read_list() } };
147
    my $mapping = Koha::Checkout->to_api_mapping;
148
149
    plan tests => scalar @all_attrs * 2;
150
151
    # Create a sample checkout
152
    my $checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
153
154
    my $unprivileged_representation = $checkout->to_api( { public => 1 } );
155
    my $privileged_representation   = $checkout->to_api;
156
157
    foreach my $attr (@all_attrs) {
158
        my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr;
159
        if ( defined($mapped) ) {
160
            ok(
161
                exists $privileged_representation->{$mapped},
162
                "Attribute '$attr' is present when privileged"
163
            );
164
            if ( exists $public_attrs->{$attr} ) {
165
                ok(
166
                    exists $unprivileged_representation->{$mapped},
167
                    "Attribute '$attr' is present when public"
168
                );
169
            } else {
170
                ok(
171
                    !exists $unprivileged_representation->{$mapped},
172
                    "Attribute '$attr' is not present when public"
173
                );
174
            }
175
        } else {
176
            ok(
177
                !exists $privileged_representation->{$attr},
178
                "Unmapped attribute '$attr' is not present when privileged"
179
            );
180
            ok(
181
                !exists $unprivileged_representation->{$attr},
182
                "Unmapped attribute '$attr' is not present when public"
183
            );
184
        }
185
    }
186
187
    $schema->storage->txn_rollback;
188
};

Return to bug 38184