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

(-)a/t/db_dependent/Koha/Patrons.t (-12 / +54 lines)
Lines 1306-1314 subtest 'search_patrons_to_anonymise' => sub { Link Here
1306
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
1306
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
1307
};
1307
};
1308
1308
1309
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited' =>
1309
subtest
1310
    sub {
1310
    'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited+ can_see_patrons_from + can_edit_items_from'
1311
    plan tests => 4;
1311
    => sub {
1312
    plan tests => 6;
1312
1313
1313
    # group1
1314
    # group1
1314
    #   + library_11
1315
    #   + library_11
Lines 1316-1323 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1316
    # group2
1317
    # group2
1317
    #   + library21
1318
    #   + library21
1318
    $nb_of_patrons = Koha::Patrons->search->count;
1319
    $nb_of_patrons = Koha::Patrons->search->count;
1319
    my $group_1    = Koha::Library::Group->new( { title => 'TEST Group 1', ft_hide_patron_info => 1 } )->store;
1320
    my $group_1 =
1320
    my $group_2    = Koha::Library::Group->new( { title => 'TEST Group 2', ft_hide_patron_info => 1 } )->store;
1321
        Koha::Library::Group->new( { title => 'TEST Group 1', ft_hide_patron_info => 1 } )
1322
        ->store;
1323
    my $group_2 =
1324
        Koha::Library::Group->new( { title => 'TEST Group 2', ft_hide_patron_info => 1 } )
1325
        ->store;
1321
    my $library_11 = $builder->build( { source => 'Branch' } );
1326
    my $library_11 = $builder->build( { source => 'Branch' } );
1322
    my $library_12 = $builder->build( { source => 'Branch' } );
1327
    my $library_12 = $builder->build( { source => 'Branch' } );
1323
    my $library_21 = $builder->build( { source => 'Branch' } );
1328
    my $library_21 = $builder->build( { source => 'Branch' } );
Lines 1329-1350 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1329
    Koha::Library::Group->new( { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store;
1334
    Koha::Library::Group->new( { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store;
1330
1335
1331
    my $sth =
1336
    my $sth =
1332
        C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 4, ?)|)
1337
        C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, ?, ?)|)
1333
        ;    # 4 for borrowers
1338
        ;
1334
             # 2 patrons from library_11 (group1)
1339
             # 2 patrons from library_11 (group1)
1335
             # patron_11_1 see patron's infos from outside its group
1340
             # patron_11_1 see patron's infos from outside its group
1336
             # Setting flags => undef to not be considered as superlibrarian
1341
             # Setting flags => undef to not be considered as superlibrarian
1337
    my $patron_11_1 = $builder->build(
1342
    my $patron_11_1 = $builder->build(
1338
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1343
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1339
    $patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} );
1344
    $patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} );
1340
    $sth->execute( $patron_11_1->borrowernumber, 'edit_borrowers' );
1345
    $sth->execute( $patron_11_1->borrowernumber, 4, 'edit_borrowers' );
1341
    $sth->execute( $patron_11_1->borrowernumber, 'view_borrower_infos_from_any_libraries' );
1346
    $sth->execute( $patron_11_1->borrowernumber, 4,'view_borrower_infos_from_any_libraries' );
1342
1347
1343
    # patron_11_2 can only see patron's info from its group
1348
    # patron_11_2 can only see patron's info from its group
1344
    my $patron_11_2 = $builder->build(
1349
    my $patron_11_2 = $builder->build(
1345
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1350
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1346
    $patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} );
1351
    $patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} );
1347
    $sth->execute( $patron_11_2->borrowernumber, 'edit_borrowers' );
1352
    $sth->execute( $patron_11_2->borrowernumber, 4, 'edit_borrowers' );
1353
    $sth->execute( $patron_11_2->borrowernumber, 9, 'edit_items' );
1348
1354
1349
    # 1 patron from library_12 (group1)
1355
    # 1 patron from library_12 (group1)
1350
    my $patron_12 = $builder->build(
1356
    my $patron_12 = $builder->build(
Lines 1355-1361 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1355
    my $patron_21 = $builder->build(
1361
    my $patron_21 = $builder->build(
1356
        { source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, } } );
1362
        { source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, } } );
1357
    $patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} );
1363
    $patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} );
1358
    $sth->execute( $patron_21->borrowernumber, 'edit_borrowers' );
1364
    $sth->execute( $patron_21->borrowernumber, 4, 'edit_borrowers' );
1359
1365
1360
    # Pfiou, we can start now!
1366
    # Pfiou, we can start now!
1361
    subtest 'libraries_where_can_see_things' => sub {
1367
    subtest 'libraries_where_can_see_things' => sub {
Lines 1378-1383 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1378
        );
1384
        );
1379
    };
1385
    };
1380
1386
1387
    subtest 'can_see_patrons_from' => sub {
1388
        plan tests => 2;
1389
        ok( $patron_11_2->can_see_patrons_from( $library_11->branchcode ), "We can see a patron from in our group" );
1390
        ok(
1391
            !$patron_11_2->can_see_patrons_from( $library_21->branchcode ),
1392
            "We cannot see a patron from outside our group without permissions"
1393
        );
1394
    };
1395
1396
    subtest 'can_edit_items_from' => sub {
1397
        plan tests => 4;
1398
        ok( $patron_11_2->can_edit_items_from( $library_11->branchcode ), "We can edit an item from in our group" );
1399
        ok(
1400
            $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"
1402
        );
1403
        $group_2->ft_limit_item_editing(1)->store();
1404
1405
        $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
1407
        # in libraries_where_can_see_things
1408
1409
        ok(
1410
            !$patron_11_2->can_edit_items_from( $library_21->branchcode ),
1411
            "We can not edit an item from outside our group as the group does limit item editing"
1412
        );
1413
1414
        $sth->execute( $patron_11_2->borrowernumber, 9, 'edit_any_item' );
1415
        $patron_11_2  = Koha::Patrons->find( $patron_11_2->borrowernumber );
1416
1417
        ok(
1418
            $patron_11_2->can_edit_items_from( $library_21->branchcode ),
1419
            "We can edit an item from outside our group as we have permission"
1420
        );
1421
1422
    };
1423
1381
    subtest 'libraries_where_can_see_patrons' => sub {
1424
    subtest 'libraries_where_can_see_patrons' => sub {
1382
        plan tests => 3;
1425
        plan tests => 3;
1383
1426
1384
- 

Return to bug 37392