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

(-)a/Koha/Object.pm (-1 / +16 lines)
Lines 406-411 sub TO_JSON { Link Here
406
            and looks_like_number( $unblessed->{$col} )
406
            and looks_like_number( $unblessed->{$col} )
407
        ) {
407
        ) {
408
408
409
            if ( $self->{_redact} ) {
410
                $unblessed->{$col} = 0;
411
            }
412
409
            # TODO: Remove once the solution for
413
            # TODO: Remove once the solution for
410
            # https://github.com/perl5-dbi/DBD-mysql/issues/212
414
            # https://github.com/perl5-dbi/DBD-mysql/issues/212
411
            # is ported to whatever distro we support by that time
415
            # is ported to whatever distro we support by that time
Lines 415-420 sub TO_JSON { Link Here
415
        elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} )
419
        elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} )
416
            and looks_like_number( $unblessed->{$col} )
420
            and looks_like_number( $unblessed->{$col} )
417
        ) {
421
        ) {
422
            if ( $self->{_redact} ) {
423
                $unblessed->{$col} = 0.00;
424
            }
418
425
419
            # TODO: Remove once the solution for
426
            # TODO: Remove once the solution for
420
            # https://github.com/perl5-dbi/DBD-mysql/issues/212
427
            # https://github.com/perl5-dbi/DBD-mysql/issues/212
Lines 423-428 sub TO_JSON { Link Here
423
            $unblessed->{$col} += 0.00;
430
            $unblessed->{$col} += 0.00;
424
        }
431
        }
425
        elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
432
        elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
433
            if ( $self->{_redact} ) {
434
                $unblessed->{$col} = "0000-01-01 00:00:01";
435
            }
426
            eval {
436
            eval {
427
                return unless $unblessed->{$col};
437
                return unless $unblessed->{$col};
428
                $unblessed->{$col} = output_pref({
438
                $unblessed->{$col} = output_pref({
Lines 431-436 sub TO_JSON { Link Here
431
                });
441
                });
432
            };
442
            };
433
        }
443
        }
444
        elsif ( $self->{_redact} ) {
445
            $unblessed->{$col} = '*****';
446
        }
434
    }
447
    }
435
    return $unblessed;
448
    return $unblessed;
436
}
449
}
Lines 552-558 Returns a representation of the object, suitable for API output. Link Here
552
sub to_api {
565
sub to_api {
553
    my ( $self, $params ) = @_;
566
    my ( $self, $params ) = @_;
554
567
555
    return unless $self->is_accessible($params);
568
    unless ( $self->is_accessible($params) ) {
569
        $self->{_redact} = 1;
570
    }
556
571
557
    my $json_object = $self->TO_JSON;
572
    my $json_object = $self->TO_JSON;
558
573
(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 2289-2295 sub set_default_messaging_preferences { Link Here
2289
2289
2290
    if ( $patron->is_accessible({ user => $logged_in_user }) ) { ... }
2290
    if ( $patron->is_accessible({ user => $logged_in_user }) ) { ... }
2291
2291
2292
This overloaded method validates wether the current I<Koha::Patron> object can be accessed
2292
This overloaded method validates whether the current I<Koha::Patron> object can be accessed
2293
by the logged in user.
2293
by the logged in user.
2294
2294
2295
Returns 0 if the I<user> parameter is missing.
2295
Returns 0 if the I<user> parameter is missing.
(-)a/t/db_dependent/Koha/Object.t (-4 / +2 lines)
Lines 555-561 subtest "to_api() tests" => sub { Link Here
555
            }
555
            }
556
        );
556
        );
557
557
558
559
        my $patron_1 = $builder->build_object(
558
        my $patron_1 = $builder->build_object(
560
            { class => 'Koha::Patrons', value => { branchcode => $library_1->id } }
559
            { class => 'Koha::Patrons', value => { branchcode => $library_1->id } }
561
        );
560
        );
Lines 565-572 subtest "to_api() tests" => sub { Link Here
565
564
566
        t::lib::Mocks::mock_userenv( { patron => $patron } );
565
        t::lib::Mocks::mock_userenv( { patron => $patron } );
567
566
568
        is( ref($patron_1->to_api({ user => $patron })), 'HASH', 'Returns the object hash' );
567
        is( $patron_1->to_api({ user => $patron })->{firstname}, $patron_1->firstname, 'Returns unredacted object hash' );
569
        is( $patron_2->to_api({ user => $patron }), undef, 'Not accessible, returns undef' );
568
        is( $patron_2->to_api({ user => $patron })->{firstname}, "*****", 'Returns redacted object hash' );
570
569
571
        $schema->storage->txn_rollback;
570
        $schema->storage->txn_rollback;
572
    };
571
    };
573
- 

Return to bug 29523