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

(-)a/Koha/Object.pm (-2 / +4 lines)
Lines 552-558 Returns a representation of the object, suitable for API output. Link Here
552
sub to_api {
552
sub to_api {
553
    my ( $self, $params ) = @_;
553
    my ( $self, $params ) = @_;
554
554
555
    return unless $self->accessible;
555
    return unless $self->is_accessible_in_context($params);
556
556
557
    my $json_object = $self->TO_JSON;
557
    my $json_object = $self->TO_JSON;
558
558
Lines 947-955 It relies on the plural class properly implementing the I<search_limited> method Link Here
947
947
948
=cut
948
=cut
949
949
950
sub accessible {
950
sub is_accessible_in_context {
951
    my ($self) = @_;
951
    my ($self) = @_;
952
952
953
    return 1 and warn "is_accessible_in_context default called";
954
953
    return $self->_get_objects_class->search_limited(
955
    return $self->_get_objects_class->search_limited(
954
        {
956
        {
955
            map { $_ => $self->$_ }
957
            map { $_ => $self->$_ }
(-)a/Koha/Patron.pm (-14 / +14 lines)
Lines 1348-1367 Return true if the patron (usually the logged in user) can see the patron's info Link Here
1348
1348
1349
sub can_see_patrons_from {
1349
sub can_see_patrons_from {
1350
    my ( $self, $branchcode ) = @_;
1350
    my ( $self, $branchcode ) = @_;
1351
    my $can = 0;
1351
    my @branches = $self->libraries_where_can_see_patrons;
1352
    if ( $self->branchcode eq $branchcode ) {
1352
    return 1 unless @branches;
1353
        $can = 1;
1353
    return any { $_ eq $branchcode } @branches;
1354
    } elsif ( $self->has_permission( { borrowers => 'view_borrower_infos_from_any_libraries' } ) ) {
1355
        $can = 1;
1356
    } elsif ( my $library_groups = $self->library->library_groups ) {
1357
        while ( my $library_group = $library_groups->next ) {
1358
            if ( $library_group->parent->has_child( $branchcode ) ) {
1359
                $can = 1;
1360
                last;
1361
            }
1362
        }
1363
    }
1364
    return $can;
1365
}
1354
}
1366
1355
1367
=head3 can_log_into
1356
=head3 can_log_into
Lines 1752-1757 sub get_extended_attribute { Link Here
1752
    return $attribute->next;
1741
    return $attribute->next;
1753
}
1742
}
1754
1743
1744
=head3 is_accessible_in_context
1745
1746
=cut
1747
1748
sub is_accessible_in_context {
1749
    my ($self, $params) = @_;
1750
1751
    my $consumer = $params->{user};
1752
    return $consumer->can_see_patron_infos($self);
1753
}
1754
1755
=head3 to_api
1755
=head3 to_api
1756
1756
1757
    my $json = $patron->to_api;
1757
    my $json = $patron->to_api;
(-)a/Koha/REST/Plugin/Objects.pm (-3 / +2 lines)
Lines 66-72 the requested object. It passes through any embeds if specified. Link Here
66
66
67
            return unless $object;
67
            return unless $object;
68
68
69
            return $object->to_api({ embed => $embed });
69
            return $object->to_api({ embed => $embed, user => $c->stash('koha.user') });
70
        }
70
        }
71
    );
71
    );
72
72
Lines 164-170 for API rendering. Link Here
164
                }
164
                }
165
            );
165
            );
166
166
167
            return $objects->to_api({ embed => $embed, public => $is_public });
167
            return $objects->to_api({ embed => $embed, public => $is_public, user => $c->stash('koha.user') });
168
        }
168
        }
169
    );
169
    );
170
}
170
}
171
- 

Return to bug 29523