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 (-1 / +50 lines)
Lines 137-139 subtest 'renewals() tests' => sub { Link Here
137
137
138
    $schema->storage->txn_rollback;
138
    $schema->storage->txn_rollback;
139
};
139
};
140
- 
140
141
subtest 'public_read_list() tests' => sub {
142
143
    $schema->storage->txn_begin;
144
145
    my @all_attrs = Koha::Checkouts->columns();
146
    my $public_attrs =
147
        { map { $_ => 1 } @{ Koha::Checkout->public_read_list() } };
148
    my $mapping = Koha::Checkout->to_api_mapping;
149
150
    plan tests => scalar @all_attrs * 2;
151
152
    # Create a sample checkout
153
    my $checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
154
155
    my $unprivileged_representation = $checkout->to_api( { public => 1 } );
156
    my $privileged_representation   = $checkout->to_api;
157
158
    foreach my $attr (@all_attrs) {
159
        my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr;
160
        if ( defined($mapped) ) {
161
            ok(
162
                exists $privileged_representation->{$mapped},
163
                "Attribute '$attr' is present when privileged"
164
            );
165
            if ( exists $public_attrs->{$attr} ) {
166
                ok(
167
                    exists $unprivileged_representation->{$mapped},
168
                    "Attribute '$attr' is present when public"
169
                );
170
            } else {
171
                ok(
172
                    !exists $unprivileged_representation->{$mapped},
173
                    "Attribute '$attr' is not present when public"
174
                );
175
            }
176
        } else {
177
            ok(
178
                !exists $privileged_representation->{$attr},
179
                "Unmapped attribute '$attr' is not present when privileged"
180
            );
181
            ok(
182
                !exists $unprivileged_representation->{$attr},
183
                "Unmapped attribute '$attr' is not present when public"
184
            );
185
        }
186
    }
187
188
    $schema->storage->txn_rollback;
189
};

Return to bug 38184