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

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1901-1906 sub can_see_things_from { Link Here
1901
        $can = 1;
1901
        $can = 1;
1902
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1902
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1903
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1903
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1904
    } else {
1905
        # This should be the case of not finding any limits above, so we can
1906
        $can = 1;
1904
    }
1907
    }
1905
    return $can;
1908
    return $can;
1906
}
1909
}
Lines 1969-1986 sub libraries_where_can_see_things { Link Here
1969
            )
1972
            )
1970
          )
1973
          )
1971
        {
1974
        {
1972
            my $library_groups = $self->library->library_groups({ $group_feature => 1 });
1975
            my $library_groups = $self->library->library_groups();
1973
            if ( $library_groups->count )
1976
            if ( $library_groups->count )
1974
            {
1977
            {
1975
                while ( my $library_group = $library_groups->next ) {
1978
                while ( my $library_group = $library_groups->next ) {
1979
                    my $root = Koha::Library::Groups->get_root_ancestor({ id => $library_group->id });
1980
                    next unless $root->$group_feature;
1976
                    my $parent = $library_group->parent;
1981
                    my $parent = $library_group->parent;
1977
                    if ( $parent->has_child( $self->branchcode ) ) {
1982
                    my @children = $parent->all_libraries;
1978
                        push @restricted_branchcodes, $parent->children->get_column('branchcode');
1983
                    foreach my $child (@children){
1984
                        push @restricted_branchcodes, $child->branchcode;
1985
1979
                    }
1986
                    }
1980
                }
1987
                }
1981
            }
1988
            }
1982
1989
1983
            @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes;
1984
        }
1990
        }
1985
    }
1991
    }
1986
1992
(-)a/t/db_dependent/Koha/Patrons.t (-10 / +22 lines)
Lines 83-88 is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have Link Here
83
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
83
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
84
is( $retrieved_patron_1->cardnumber, $new_patron_1->cardnumber, 'Find a patron by borrowernumber should return the correct patron' );
84
is( $retrieved_patron_1->cardnumber, $new_patron_1->cardnumber, 'Find a patron by borrowernumber should return the correct patron' );
85
85
86
87
86
subtest 'library' => sub {
88
subtest 'library' => sub {
87
    plan tests => 2;
89
    plan tests => 2;
88
    is( $retrieved_patron_1->library->branchcode, $library->{branchcode}, 'Koha::Patron->library should return the correct library' );
90
    is( $retrieved_patron_1->library->branchcode, $library->{branchcode}, 'Koha::Patron->library should return the correct library' );
Lines 1365-1386 subtest Link Here
1365
1367
1366
    # Pfiou, we can start now!
1368
    # Pfiou, we can start now!
1367
    subtest 'libraries_where_can_see_things' => sub {
1369
    subtest 'libraries_where_can_see_things' => sub {
1368
        plan tests => 2;
1370
        plan tests => 4;
1369
        t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } );
1371
        t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } );
1370
        my $params = {
1372
        my $params = {
1371
            permission    => 'editcatalogue',
1373
            permission    => 'borrowers',
1372
            subpermission => 'edit_any_item',
1374
            subpermission => 'view_borrower_infos_from_any_libraries',
1373
            group_feature => 'ft_limit_item_editing',
1375
            group_feature => 'ft_hide_patron_info',
1374
        };
1376
        };
1375
        my @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1377
        my @branchcodes = $patron_11_1->libraries_where_can_see_things($params);
1376
        is_deeply(
1378
        is_deeply(
1377
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1379
            \@branchcodes, [ ],
1378
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1380
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1379
        );
1381
        );
1382
        @branchcodes = $patron_11_1->libraries_where_can_see_things($params);
1383
        is_deeply(
1384
            \@branchcodes, [ ],
1385
            q|confirming second/cached request is the same patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1386
        );
1387
1380
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1388
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1381
        is_deeply(
1389
        is_deeply(
1382
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1390
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1383
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1391
            q|patron_11_2 can only view from group|
1392
        );
1393
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1394
        is_deeply(
1395
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1396
            q|confirming second/cached request is the same patron_11_2 can only view from group|
1384
        );
1397
        );
1385
    };
1398
    };
1386
1399
Lines 1400-1406 subtest Link Here
1400
            $patron_11_2->can_edit_items_from( $library_21->branchcode ),
1413
            $patron_11_2->can_edit_items_from( $library_21->branchcode ),
1401
            "We can edit an item from outside our group as the group does not limit item editing"
1414
            "We can edit an item from outside our group as the group does not limit item editing"
1402
        );
1415
        );
1403
        $group_2->ft_limit_item_editing(1)->store();
1416
        $group_1->ft_limit_item_editing(1)->store();
1404
1417
1405
        $patron_11_2  = Koha::Patrons->find( $patron_11_2->borrowernumber );
1418
        $patron_11_2  = Koha::Patrons->find( $patron_11_2->borrowernumber );
1406
        #FIXME We refetch the patron because library lists are cached in an extra hash key
1419
        #FIXME We refetch the patron because library lists are cached in an extra hash key
1407
- 

Return to bug 37392