|
Lines 405-415
sub TO_JSON {
Link Here
|
| 405 |
elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) |
405 |
elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) |
| 406 |
and looks_like_number( $unblessed->{$col} ) |
406 |
and looks_like_number( $unblessed->{$col} ) |
| 407 |
) { |
407 |
) { |
| 408 |
|
|
|
| 409 |
if ( $self->{_redact} ) { |
| 410 |
$unblessed->{$col} = 0; |
| 411 |
} |
| 412 |
|
| 413 |
# TODO: Remove once the solution for |
408 |
# TODO: Remove once the solution for |
| 414 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
409 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
| 415 |
# is ported to whatever distro we support by that time |
410 |
# is ported to whatever distro we support by that time |
|
Lines 419-428
sub TO_JSON {
Link Here
|
| 419 |
elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) |
414 |
elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) |
| 420 |
and looks_like_number( $unblessed->{$col} ) |
415 |
and looks_like_number( $unblessed->{$col} ) |
| 421 |
) { |
416 |
) { |
| 422 |
if ( $self->{_redact} ) { |
|
|
| 423 |
$unblessed->{$col} = 0.00; |
| 424 |
} |
| 425 |
|
| 426 |
# TODO: Remove once the solution for |
417 |
# TODO: Remove once the solution for |
| 427 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
418 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
| 428 |
# is ported to whatever distro we support by that time |
419 |
# is ported to whatever distro we support by that time |
|
Lines 430-438
sub TO_JSON {
Link Here
|
| 430 |
$unblessed->{$col} += 0.00; |
421 |
$unblessed->{$col} += 0.00; |
| 431 |
} |
422 |
} |
| 432 |
elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) { |
423 |
elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) { |
| 433 |
if ( $self->{_redact} ) { |
|
|
| 434 |
$unblessed->{$col} = "0000-01-01 00:00:01"; |
| 435 |
} |
| 436 |
eval { |
424 |
eval { |
| 437 |
return unless $unblessed->{$col}; |
425 |
return unless $unblessed->{$col}; |
| 438 |
$unblessed->{$col} = output_pref({ |
426 |
$unblessed->{$col} = output_pref({ |
|
Lines 441-449
sub TO_JSON {
Link Here
|
| 441 |
}); |
429 |
}); |
| 442 |
}; |
430 |
}; |
| 443 |
} |
431 |
} |
| 444 |
elsif ( $self->{_redact} ) { |
|
|
| 445 |
$unblessed->{$col} = '*****'; |
| 446 |
} |
| 447 |
} |
432 |
} |
| 448 |
return $unblessed; |
433 |
return $unblessed; |
| 449 |
} |
434 |
} |
|
Lines 565-574
Returns a representation of the object, suitable for API output.
Link Here
|
| 565 |
sub to_api { |
550 |
sub to_api { |
| 566 |
my ( $self, $params ) = @_; |
551 |
my ( $self, $params ) = @_; |
| 567 |
|
552 |
|
| 568 |
unless ( $self->is_accessible($params) ) { |
|
|
| 569 |
$self->{_redact} = 1; |
| 570 |
} |
| 571 |
|
| 572 |
my $json_object = $self->TO_JSON; |
553 |
my $json_object = $self->TO_JSON; |
| 573 |
|
554 |
|
| 574 |
# Make sure we duplicate the $params variable to avoid |
555 |
# Make sure we duplicate the $params variable to avoid |
|
Lines 600-605
sub to_api {
Link Here
|
| 600 |
} |
581 |
} |
| 601 |
} |
582 |
} |
| 602 |
|
583 |
|
|
|
584 |
# Remove forbidden attributes if required (including their coded values) |
| 585 |
if ( !$self->is_accessible($params) ) { |
| 586 |
for my $field ( keys %{$json_object} ) { |
| 587 |
unless ( any { $_ eq $field } @{ $self->unredact_list } ) { |
| 588 |
$json_object->{$field} = '#####' |
| 589 |
} |
| 590 |
|
| 591 |
} |
| 592 |
|
| 593 |
if ($strings) { |
| 594 |
foreach my $field ( keys %{$string_map} ) { |
| 595 |
unless ( any { $_ eq $field } @{ $self->unredact_list } ) { |
| 596 |
$string_map->{$field} = '#####' |
| 597 |
} |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 603 |
my $to_api_mapping = $self->to_api_mapping; |
602 |
my $to_api_mapping = $self->to_api_mapping; |
| 604 |
|
603 |
|
| 605 |
# Rename attributes and coded values if there's a mapping |
604 |
# Rename attributes and coded values if there's a mapping |
|
Lines 732-737
sub public_read_list
Link Here
|
| 732 |
return []; |
731 |
return []; |
| 733 |
} |
732 |
} |
| 734 |
|
733 |
|
|
|
734 |
=head3 unredact_list |
| 735 |
|
| 736 |
my @unredact_list = @{$object->unredact_list}; |
| 737 |
|
| 738 |
Generic method that returns the list of database columns that are allowed to |
| 739 |
be passed to render objects on the API when the user making the request should |
| 740 |
not ordinarily have unrestricted access to the data (as returned by the is_accesible method). |
| 741 |
|
| 742 |
Note: this only returns an empty I<arrayref>. Each class should have its |
| 743 |
own implementation. |
| 744 |
|
| 745 |
=cut |
| 746 |
|
| 747 |
sub unredact_list |
| 748 |
{ |
| 749 |
return []; |
| 750 |
} |
| 751 |
|
| 735 |
=head3 from_api_mapping |
752 |
=head3 from_api_mapping |
| 736 |
|
753 |
|
| 737 |
my $mapping = $object->from_api_mapping; |
754 |
my $mapping = $object->from_api_mapping; |