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

(-)a/Koha/Patron.pm (-8 / +8 lines)
Lines 1798-1810 sub can_see_things_from { Link Here
1798
        $can = 1;
1798
        $can = 1;
1799
    } elsif ( $self->has_permission( { $permission => $subpermission } ) ) {
1799
    } elsif ( $self->has_permission( { $permission => $subpermission } ) ) {
1800
        $can = 1;
1800
        $can = 1;
1801
    } elsif ( my $library_groups = $self->library->library_groups ) {
1801
    } elsif ( my @branches = $self->libraries_where_can_see_patrons ) {
1802
        while ( my $library_group = $library_groups->next ) {
1802
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1803
            if ( $library_group->parent->has_child( $branchcode ) ) {
1804
                $can = 1;
1805
                last;
1806
            }
1807
        }
1808
    }
1803
    }
1809
    return $can;
1804
    return $can;
1810
}
1805
}
Lines 1855-1860 sub libraries_where_can_see_things { Link Here
1855
    my $subpermission = $params->{subpermission};
1850
    my $subpermission = $params->{subpermission};
1856
    my $group_feature = $params->{group_feature};
1851
    my $group_feature = $params->{group_feature};
1857
1852
1853
    return $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"}
1854
        if exists( $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} );
1855
1858
    my $userenv = C4::Context->userenv;
1856
    my $userenv = C4::Context->userenv;
1859
1857
1860
    return () unless $userenv; # For tests, but userenv should be defined in tests...
1858
    return () unless $userenv; # For tests, but userenv should be defined in tests...
Lines 1888-1894 sub libraries_where_can_see_things { Link Here
1888
    @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes;
1886
    @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes;
1889
    @restricted_branchcodes = uniq(@restricted_branchcodes);
1887
    @restricted_branchcodes = uniq(@restricted_branchcodes);
1890
    @restricted_branchcodes = sort(@restricted_branchcodes);
1888
    @restricted_branchcodes = sort(@restricted_branchcodes);
1891
    return @restricted_branchcodes;
1889
1890
    $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} = \@restricted_branchcodes;
1891
    return @{ $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} };
1892
}
1892
}
1893
1893
1894
=head3 has_permission
1894
=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