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

(-)a/Koha/Patron.pm (-5 / +57 lines)
Lines 1125-1134 Return true if the patron (usually the logged in user) can see the patron's info Link Here
1125
1125
1126
sub can_see_patrons_from {
1126
sub can_see_patrons_from {
1127
    my ( $self, $branchcode ) = @_;
1127
    my ( $self, $branchcode ) = @_;
1128
1129
    return $self->can_see_things_from(
1130
        {
1131
            branchcode => $branchcode,
1132
            permission => 'borrowers',
1133
            subpermission => 'view_borrower_infos_from_any_libraries',
1134
        }
1135
    );
1136
}
1137
1138
=head3 can_see_things_from
1139
1140
my $can_see = $thing->can_see_things_from( $branchcode );
1141
1142
Return true if this "patron" ( usally the logged in user ) can perform some action on the given thing
1143
1144
=cut
1145
1146
sub can_see_things_from {
1147
    my ( $self, $params ) = @_;
1148
    my $branchcode    = $params->{branchcode};
1149
    my $permission    = $params->{permission};
1150
    my $subpermission = $params->{subpermission};
1151
1128
    my $can = 0;
1152
    my $can = 0;
1129
    if ( $self->branchcode eq $branchcode ) {
1153
    if ( $self->branchcode eq $branchcode ) {
1130
        $can = 1;
1154
        $can = 1;
1131
    } elsif ( $self->has_permission( { borrowers => 'view_borrower_infos_from_any_libraries' } ) ) {
1155
    } elsif ( $self->has_permission( { $permission => $subpermission } ) ) {
1132
        $can = 1;
1156
        $can = 1;
1133
    } elsif ( my $library_groups = $self->library->library_groups ) {
1157
    } elsif ( my $library_groups = $self->library->library_groups ) {
1134
        while ( my $library_group = $library_groups->next ) {
1158
        while ( my $library_group = $library_groups->next ) {
Lines 1154-1160 An empty array means no restriction, the patron can see patron's infos from any Link Here
1154
=cut
1178
=cut
1155
1179
1156
sub libraries_where_can_see_patrons {
1180
sub libraries_where_can_see_patrons {
1157
    my ( $self ) = @_;
1181
    my ($self) = @_;
1182
1183
    return $self->libraries_where_can_see_things(
1184
        {
1185
            permission    => 'borrowers',
1186
            subpermission => 'view_borrower_infos_from_any_libraries',
1187
            group_feature => 'ft_hide_patron_info',
1188
        }
1189
    );
1190
}
1191
1192
=head3 libraries_where_can_see_things
1193
1194
my $libraries = $thing-libraries_where_can_see_things;
1195
1196
Returns a list of libraries where an aribitarary action is allowd to be taken by the logged in librarian
1197
against an object based on some branchcode related to the object ( patron branchcode, item homebranch, etc ).
1198
1199
We are supposing here that the object is related to the logged in librarian (use of C4::Context::only_my_library)
1200
1201
An empty array means no restriction, the thing can see thing's infos from any libraries.
1202
1203
=cut
1204
1205
sub libraries_where_can_see_things {
1206
    my ( $self, $params ) = @_;
1207
    my $permission    = $params->{permission};
1208
    my $subpermission = $params->{subpermission};
1209
    my $group_feature = $params->{group_feature};
1210
1158
    my $userenv = C4::Context->userenv;
1211
    my $userenv = C4::Context->userenv;
1159
1212
1160
    return () unless $userenv; # For tests, but userenv should be defined in tests...
1213
    return () unless $userenv; # For tests, but userenv should be defined in tests...
Lines 1166-1176 sub libraries_where_can_see_patrons { Link Here
1166
    else {
1219
    else {
1167
        unless (
1220
        unless (
1168
            $self->has_permission(
1221
            $self->has_permission(
1169
                { borrowers => 'view_borrower_infos_from_any_libraries' }
1222
                { $permission => $subpermission }
1170
            )
1223
            )
1171
          )
1224
          )
1172
        {
1225
        {
1173
            my $library_groups = $self->library->library_groups({ ft_hide_patron_info => 1 });
1226
            my $library_groups = $self->library->library_groups({ $group_feature => 1 });
1174
            if ( $library_groups->count )
1227
            if ( $library_groups->count )
1175
            {
1228
            {
1176
                while ( my $library_group = $library_groups->next ) {
1229
                while ( my $library_group = $library_groups->next ) {
1177
- 

Return to bug 20256