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

(-)a/Koha/Patron.pm (-8 / +8 lines)
Lines 1787-1799 sub can_see_things_from { Link Here
1787
        $can = 1;
1787
        $can = 1;
1788
    } elsif ( $self->has_permission( { $permission => $subpermission } ) ) {
1788
    } elsif ( $self->has_permission( { $permission => $subpermission } ) ) {
1789
        $can = 1;
1789
        $can = 1;
1790
    } elsif ( my $library_groups = $self->library->library_groups ) {
1790
    } elsif ( my @branches = $self->libraries_where_can_see_patrons ) {
1791
        while ( my $library_group = $library_groups->next ) {
1791
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1792
            if ( $library_group->parent->has_child( $branchcode ) ) {
1793
                $can = 1;
1794
                last;
1795
            }
1796
        }
1797
    }
1792
    }
1798
    return $can;
1793
    return $can;
1799
}
1794
}
Lines 1844-1849 sub libraries_where_can_see_things { Link Here
1844
    my $subpermission = $params->{subpermission};
1839
    my $subpermission = $params->{subpermission};
1845
    my $group_feature = $params->{group_feature};
1840
    my $group_feature = $params->{group_feature};
1846
1841
1842
    return $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"}
1843
        if exists( $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} );
1844
1847
    my $userenv = C4::Context->userenv;
1845
    my $userenv = C4::Context->userenv;
1848
1846
1849
    return () unless $userenv; # For tests, but userenv should be defined in tests...
1847
    return () unless $userenv; # For tests, but userenv should be defined in tests...
Lines 1877-1883 sub libraries_where_can_see_things { Link Here
1877
    @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes;
1875
    @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes;
1878
    @restricted_branchcodes = uniq(@restricted_branchcodes);
1876
    @restricted_branchcodes = uniq(@restricted_branchcodes);
1879
    @restricted_branchcodes = sort(@restricted_branchcodes);
1877
    @restricted_branchcodes = sort(@restricted_branchcodes);
1880
    return @restricted_branchcodes;
1878
1879
    $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} = \@restricted_branchcodes;
1880
    return @{ $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} };
1881
}
1881
}
1882
1882
1883
=head3 has_permission
1883
=head3 has_permission
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +5 lines)
Lines 1350-1360 subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited Link Here
1350
        plan tests => 6;
1350
        plan tests => 6;
1351
1351
1352
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1352
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1353
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1353
        is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| );
1354
        is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| );
1354
        is( $patron_11_1->can_see_patron_infos( $patron_12 ),   1, q|patron_11_1 can see patron_12, from its group| );
1355
        is( $patron_11_1->can_see_patron_infos( $patron_12 ),   1, q|patron_11_1 can see patron_12, from its group| );
1355
        is( $patron_11_1->can_see_patron_infos( $patron_21 ),   1, q|patron_11_1 can see patron_11_2, from another group| );
1356
        is( $patron_11_1->can_see_patron_infos( $patron_21 ),   1, q|patron_11_1 can see patron_11_2, from another group| );
1356
1357
1357
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1358
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1359
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1358
        is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| );
1360
        is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| );
1359
        is( $patron_11_2->can_see_patron_infos( $patron_12 ),   1, q|patron_11_2 can see patron_12, from its group| );
1361
        is( $patron_11_2->can_see_patron_infos( $patron_12 ),   1, q|patron_11_2 can see patron_12, from its group| );
1360
        is( $patron_11_2->can_see_patron_infos( $patron_21 ),   0, q|patron_11_2 can NOT see patron_21, from another group| );
1362
        is( $patron_11_2->can_see_patron_infos( $patron_21 ),   0, q|patron_11_2 can NOT see patron_21, from another group| );
Lines 1363-1377 subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited Link Here
1363
        plan tests => 6;
1365
        plan tests => 6;
1364
1366
1365
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1367
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1368
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1366
        my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests
1369
        my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests
1367
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1370
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1368
        is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' );
1371
        is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' );
1369
1372
1370
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1373
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1374
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1371
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1375
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1372
        is( Koha::Patrons->search_limited->count, 3, 'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12' );
1376
        is( Koha::Patrons->search_limited->count, 3, 'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12' );
1373
1377
1374
        t::lib::Mocks::mock_userenv({ patron => $patron_21 });
1378
        t::lib::Mocks::mock_userenv({ patron => $patron_21 });
1379
        $patron_21 = Koha::Patrons->find( $patron_21->borrowernumber );
1375
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1380
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1376
        is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' );
1381
        is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' );
1377
    };
1382
    };
1378
- 

Return to bug 29523