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

(-)a/Koha/Checkout.pm (+15 lines)
Lines 222-227 sub to_api_mapping { Link Here
222
    };
222
    };
223
}
223
}
224
224
225
=head3 public_read_list
226
227
This method returns the list of publicly readable database fields for both API and UI output purposes
228
229
=cut
230
231
sub public_read_list {
232
    return [
233
        'checkin_library', 'issue_id',        'borrowernumber',
234
        'itemnumber',      'date_due',        'branchcode',
235
        'returndate',      'lastreneweddate', 'issuedate',
236
        'notedate',        'noteseen'
237
    ];
238
}
239
225
=head3 claim_returned
240
=head3 claim_returned
226
241
227
  my $return_claim = $checkout->claim_returned();
242
  my $return_claim = $checkout->claim_returned();
(-)a/t/db_dependent/Koha/Checkout.t (-1 / +50 lines)
Lines 77-79 subtest 'renewals() tests' => sub { Link Here
77
77
78
    $schema->storage->txn_rollback;
78
    $schema->storage->txn_rollback;
79
};
79
};
80
- 
80
81
subtest 'public_read_list() tests' => sub {
82
83
    $schema->storage->txn_begin;
84
85
    my @all_attrs = Koha::Checkouts->columns();
86
    my $public_attrs =
87
        { map { $_ => 1 } @{ Koha::Checkout->public_read_list() } };
88
    my $mapping = Koha::Checkout->to_api_mapping;
89
90
    plan tests => scalar @all_attrs * 2;
91
92
    # Create a sample checkout
93
    my $checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
94
95
    my $unprivileged_representation = $checkout->to_api( { public => 1 } );
96
    my $privileged_representation   = $checkout->to_api;
97
98
    foreach my $attr (@all_attrs) {
99
        my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr;
100
        if ( defined($mapped) ) {
101
            ok(
102
                exists $privileged_representation->{$mapped},
103
                "Attribute '$attr' is present when privileged"
104
            );
105
            if ( exists $public_attrs->{$attr} ) {
106
                ok(
107
                    exists $unprivileged_representation->{$mapped},
108
                    "Attribute '$attr' is present when public"
109
                );
110
            } else {
111
                ok(
112
                    !exists $unprivileged_representation->{$mapped},
113
                    "Attribute '$attr' is not present when public"
114
                );
115
            }
116
        } else {
117
            ok(
118
                !exists $privileged_representation->{$attr},
119
                "Unmapped attribute '$attr' is not present when privileged"
120
            );
121
            ok(
122
                !exists $unprivileged_representation->{$attr},
123
                "Unmapped attribute '$attr' is not present when public"
124
            );
125
        }
126
    }
127
128
    $schema->storage->txn_rollback;
129
};

Return to bug 38184