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

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1899-1904 sub can_see_things_from { Link Here
1899
        $can = 1;
1899
        $can = 1;
1900
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1900
    } elsif ( my @branches = $self->libraries_where_can_see_things($params) ) {
1901
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1901
        $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0;
1902
    } else {
1903
        # This should be the case of not finding any limits above, so we can
1904
        $can = 1;
1902
    }
1905
    }
1903
    return $can;
1906
    return $can;
1904
}
1907
}
Lines 1967-1984 sub libraries_where_can_see_things { Link Here
1967
            )
1970
            )
1968
          )
1971
          )
1969
        {
1972
        {
1970
            my $library_groups = $self->library->library_groups({ $group_feature => 1 });
1973
            my $library_groups = $self->library->library_groups();
1971
            if ( $library_groups->count )
1974
            if ( $library_groups->count )
1972
            {
1975
            {
1973
                while ( my $library_group = $library_groups->next ) {
1976
                while ( my $library_group = $library_groups->next ) {
1977
                    my $root = Koha::Library::Groups->get_root_ancestor({ id => $library_group->id });
1978
                    next unless $root->$group_feature;
1974
                    my $parent = $library_group->parent;
1979
                    my $parent = $library_group->parent;
1975
                    if ( $parent->has_child( $self->branchcode ) ) {
1980
                    my @children = $parent->all_libraries;
1976
                        push @restricted_branchcodes, $parent->children->get_column('branchcode');
1981
                    foreach my $child (@children){
1982
                        push @restricted_branchcodes, $child->branchcode;
1983
1977
                    }
1984
                    }
1978
                }
1985
                }
1979
            }
1986
            }
1980
1987
1981
            @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes;
1982
        }
1988
        }
1983
    }
1989
    }
1984
1990
(-)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 1343-1364 subtest Link Here
1343
1345
1344
    # Pfiou, we can start now!
1346
    # Pfiou, we can start now!
1345
    subtest 'libraries_where_can_see_things' => sub {
1347
    subtest 'libraries_where_can_see_things' => sub {
1346
        plan tests => 2;
1348
        plan tests => 4;
1347
        t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } );
1349
        t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } );
1348
        my $params = {
1350
        my $params = {
1349
            permission    => 'editcatalogue',
1351
            permission    => 'borrowers',
1350
            subpermission => 'edit_any_item',
1352
            subpermission => 'view_borrower_infos_from_any_libraries',
1351
            group_feature => 'ft_limit_item_editing',
1353
            group_feature => 'ft_hide_patron_info',
1352
        };
1354
        };
1353
        my @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1355
        my @branchcodes = $patron_11_1->libraries_where_can_see_things($params);
1354
        is_deeply(
1356
        is_deeply(
1355
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1357
            \@branchcodes, [ ],
1356
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1358
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1357
        );
1359
        );
1360
        @branchcodes = $patron_11_1->libraries_where_can_see_things($params);
1361
        is_deeply(
1362
            \@branchcodes, [ ],
1363
            q|confirming second/cached request is the same patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1364
        );
1365
1358
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1366
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1359
        is_deeply(
1367
        is_deeply(
1360
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1368
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1361
            q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction|
1369
            q|patron_11_2 can only view from group|
1370
        );
1371
        @branchcodes = $patron_11_2->libraries_where_can_see_things($params);
1372
        is_deeply(
1373
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1374
            q|confirming second/cached request is the same patron_11_2 can only view from group|
1362
        );
1375
        );
1363
    };
1376
    };
1364
1377
Lines 1378-1384 subtest Link Here
1378
            $patron_11_2->can_edit_items_from( $library_21->branchcode ),
1391
            $patron_11_2->can_edit_items_from( $library_21->branchcode ),
1379
            "We can edit an item from outside our group as the group does not limit item editing"
1392
            "We can edit an item from outside our group as the group does not limit item editing"
1380
        );
1393
        );
1381
        $group_2->ft_limit_item_editing(1)->store();
1394
        $group_1->ft_limit_item_editing(1)->store();
1382
1395
1383
        $patron_11_2  = Koha::Patrons->find( $patron_11_2->borrowernumber );
1396
        $patron_11_2  = Koha::Patrons->find( $patron_11_2->borrowernumber );
1384
        #FIXME We refetch the patron because library lists are cached in an extra hash key
1397
        #FIXME We refetch the patron because library lists are cached in an extra hash key
1385
- 

Return to bug 37392