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

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1926-1931 sub can_see_things_from { Link Here
1926
        $can = 1;
1926
        $can = 1;
1927
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1927
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1928
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1928
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1929
    } else {
1930
        # This should be the case of not finding any limits above, so we can
1931
        $can = 1;
1929
    }
1932
    }
1930
    return $can;
1933
    return $can;
1931
}
1934
}
Lines 1994-2011 sub libraries_where_can_see_things { Link Here
1994
            )
1997
            )
1995
          )
1998
          )
1996
        {
1999
        {
1997
            my $library_groups = $self->library->library_groups({ $group_feature => 1 });
2000
            my $library_groups = $self->library->library_groups();
1998
            if ( $library_groups->count )
2001
            if ( $library_groups->count )
1999
            {
2002
            {
2000
                while ( my $library_group = $library_groups->next ) {
2003
                while ( my $library_group = $library_groups->next ) {
2004
                    my $root = Koha::Library::Groups->get_root_ancestor({ id => $library_group->id });
2005
                    next unless $root->$group_feature;
2001
                    my $parent = $library_group->parent;
2006
                    my $parent = $library_group->parent;
2002
                    if ( $parent->has_child( $self->branchcode ) ) {
2007
                    my @children = $parent->all_libraries;
2003
                        push @restricted_branchcodes, $parent->children->get_column('branchcode');
2008
                    foreach my $child (@children){
2009
                        push @restricted_branchcodes, $child->branchcode;
2010
2004
                    }
2011
                    }
2005
                }
2012
                }
2006
            }
2013
            }
2007
2014
2008
            @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes;
2009
        }
2015
        }
2010
    }
2016
    }
2011
2017
(-)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