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

(-)a/t/db_dependent/Koha/Patrons.t (-42 / +66 lines)
Lines 1284-1290 subtest 'search_patrons_to_anonymise' => sub { Link Here
1284
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
1284
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
1285
};
1285
};
1286
1286
1287
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited' => sub {
1287
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited' =>
1288
    sub {
1288
    plan tests => 4;
1289
    plan tests => 4;
1289
1290
1290
    # group1
1291
    # group1
Lines 1293-1330 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1293
    # group2
1294
    # group2
1294
    #   + library21
1295
    #   + library21
1295
    $nb_of_patrons = Koha::Patrons->search->count;
1296
    $nb_of_patrons = Koha::Patrons->search->count;
1296
    my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_hide_patron_info => 1 } )->store;
1297
    my $group_1    = Koha::Library::Group->new( { title => 'TEST Group 1', ft_hide_patron_info => 1 } )->store;
1297
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_hide_patron_info => 1 } )->store;
1298
    my $group_2    = Koha::Library::Group->new( { title => 'TEST Group 2', ft_hide_patron_info => 1 } )->store;
1298
    my $library_11 = $builder->build( { source => 'Branch' } );
1299
    my $library_11 = $builder->build( { source => 'Branch' } );
1299
    my $library_12 = $builder->build( { source => 'Branch' } );
1300
    my $library_12 = $builder->build( { source => 'Branch' } );
1300
    my $library_21 = $builder->build( { source => 'Branch' } );
1301
    my $library_21 = $builder->build( { source => 'Branch' } );
1301
    $library_11 = Koha::Libraries->find( $library_11->{branchcode} );
1302
    $library_11 = Koha::Libraries->find( $library_11->{branchcode} );
1302
    $library_12 = Koha::Libraries->find( $library_12->{branchcode} );
1303
    $library_12 = Koha::Libraries->find( $library_12->{branchcode} );
1303
    $library_21 = Koha::Libraries->find( $library_21->{branchcode} );
1304
    $library_21 = Koha::Libraries->find( $library_21->{branchcode} );
1304
    Koha::Library::Group->new(
1305
    Koha::Library::Group->new( { branchcode => $library_11->branchcode, parent_id => $group_1->id } )->store;
1305
        { branchcode => $library_11->branchcode, parent_id => $group_1->id } )->store;
1306
    Koha::Library::Group->new( { branchcode => $library_12->branchcode, parent_id => $group_1->id } )->store;
1306
    Koha::Library::Group->new(
1307
    Koha::Library::Group->new( { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store;
1307
        { branchcode => $library_12->branchcode, parent_id => $group_1->id } )->store;
1308
1308
    Koha::Library::Group->new(
1309
    my $sth =
1309
        { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store;
1310
        C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 4, ?)|)
1310
1311
        ;    # 4 for borrowers
1311
    my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 4, ?)|); # 4 for borrowers
1312
             # 2 patrons from library_11 (group1)
1312
    # 2 patrons from library_11 (group1)
1313
             # patron_11_1 see patron's infos from outside its group
1313
    # patron_11_1 see patron's infos from outside its group
1314
             # Setting flags => undef to not be considered as superlibrarian
1314
    # Setting flags => undef to not be considered as superlibrarian
1315
    my $patron_11_1 = $builder->build(
1315
    my $patron_11_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, }});
1316
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1316
    $patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} );
1317
    $patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} );
1317
    $sth->execute( $patron_11_1->borrowernumber, 'edit_borrowers' );
1318
    $sth->execute( $patron_11_1->borrowernumber, 'edit_borrowers' );
1318
    $sth->execute( $patron_11_1->borrowernumber, 'view_borrower_infos_from_any_libraries' );
1319
    $sth->execute( $patron_11_1->borrowernumber, 'view_borrower_infos_from_any_libraries' );
1320
1319
    # patron_11_2 can only see patron's info from its group
1321
    # patron_11_2 can only see patron's info from its group
1320
    my $patron_11_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, }});
1322
    my $patron_11_2 = $builder->build(
1323
        { source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } );
1321
    $patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} );
1324
    $patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} );
1322
    $sth->execute( $patron_11_2->borrowernumber, 'edit_borrowers' );
1325
    $sth->execute( $patron_11_2->borrowernumber, 'edit_borrowers' );
1326
1323
    # 1 patron from library_12 (group1)
1327
    # 1 patron from library_12 (group1)
1324
    my $patron_12 = $builder->build({ source => 'Borrower', value => { branchcode => $library_12->branchcode, flags => undef, }});
1328
    my $patron_12 = $builder->build(
1329
        { source => 'Borrower', value => { branchcode => $library_12->branchcode, flags => undef, } } );
1325
    $patron_12 = Koha::Patrons->find( $patron_12->{borrowernumber} );
1330
    $patron_12 = Koha::Patrons->find( $patron_12->{borrowernumber} );
1331
1326
    # 1 patron from library_21 (group2) can only see patron's info from its group
1332
    # 1 patron from library_21 (group2) can only see patron's info from its group
1327
    my $patron_21 = $builder->build({ source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, }});
1333
    my $patron_21 = $builder->build(
1334
        { source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, } } );
1328
    $patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} );
1335
    $patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} );
1329
    $sth->execute( $patron_21->borrowernumber, 'edit_borrowers' );
1336
    $sth->execute( $patron_21->borrowernumber, 'edit_borrowers' );
1330
1337
Lines 1354-1410 subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_ Link Here
1354
1361
1355
        my @branchcodes;
1362
        my @branchcodes;
1356
1363
1357
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1364
        t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } );
1358
        @branchcodes = $patron_11_1->libraries_where_can_see_patrons;
1365
        @branchcodes = $patron_11_1->libraries_where_can_see_patrons;
1359
        is_deeply( \@branchcodes, [], q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| );
1366
        is_deeply( \@branchcodes, [], q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| );
1360
1367
1361
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1368
        t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } );
1362
        @branchcodes = $patron_11_2->libraries_where_can_see_patrons;
1369
        @branchcodes = $patron_11_2->libraries_where_can_see_patrons;
1363
        is_deeply( \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], q|patron_11_2 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| );
1370
        is_deeply(
1371
            \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ],
1372
            q|patron_11_2 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group|
1373
        );
1364
1374
1365
        t::lib::Mocks::mock_userenv({ patron => $patron_21 });
1375
        t::lib::Mocks::mock_userenv( { patron => $patron_21 } );
1366
        @branchcodes = $patron_21->libraries_where_can_see_patrons;
1376
        @branchcodes = $patron_21->libraries_where_can_see_patrons;
1367
        is_deeply( \@branchcodes, [$library_21->branchcode], q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| );
1377
        is_deeply(
1378
            \@branchcodes, [ $library_21->branchcode ],
1379
            q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group|
1380
        );
1368
    };
1381
    };
1369
    subtest 'can_see_patron_infos' => sub {
1382
    subtest 'can_see_patron_infos' => sub {
1370
        plan tests => 6;
1383
        plan tests => 6;
1371
1384
1372
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1385
        t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } );
1373
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1386
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1374
        is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| );
1387
        is( $patron_11_1->can_see_patron_infos($patron_11_2), 1, q|patron_11_1 can see patron_11_2, from its library| );
1375
        is( $patron_11_1->can_see_patron_infos( $patron_12 ),   1, q|patron_11_1 can see patron_12, from its group| );
1388
        is( $patron_11_1->can_see_patron_infos($patron_12),   1, q|patron_11_1 can see patron_12, from its group| );
1376
        is( $patron_11_1->can_see_patron_infos( $patron_21 ),   1, q|patron_11_1 can see patron_11_2, from another group| );
1389
        is( $patron_11_1->can_see_patron_infos($patron_21), 1, q|patron_11_1 can see patron_11_2, from another group| );
1377
1390
1378
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1391
        t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } );
1379
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1392
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1380
        is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| );
1393
        is( $patron_11_2->can_see_patron_infos($patron_11_1), 1, q|patron_11_2 can see patron_11_1, from its library| );
1381
        is( $patron_11_2->can_see_patron_infos( $patron_12 ),   1, q|patron_11_2 can see patron_12, from its group| );
1394
        is( $patron_11_2->can_see_patron_infos($patron_12),   1, q|patron_11_2 can see patron_12, from its group| );
1382
        is( $patron_11_2->can_see_patron_infos( $patron_21 ),   0, q|patron_11_2 can NOT see patron_21, from another group| );
1395
        is(
1396
            $patron_11_2->can_see_patron_infos($patron_21), 0,
1397
            q|patron_11_2 can NOT see patron_21, from another group|
1398
        );
1383
    };
1399
    };
1384
    subtest 'search_limited' => sub {
1400
    subtest 'search_limited' => sub {
1385
        plan tests => 6;
1401
        plan tests => 6;
1386
1402
1387
        t::lib::Mocks::mock_userenv({ patron => $patron_11_1 });
1403
        t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } );
1388
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1404
        $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber );
1389
        my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests
1405
        my $total_number_of_patrons = $nb_of_patrons + 4;    #we added four in these tests
1390
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1406
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1391
        is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' );
1407
        is(
1408
            Koha::Patrons->search_limited->count, $total_number_of_patrons,
1409
            'patron_11_1 is allowed to see all patrons'
1410
        );
1392
1411
1393
        t::lib::Mocks::mock_userenv({ patron => $patron_11_2 });
1412
        t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } );
1394
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1413
        $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber );
1395
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1414
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1396
        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' );
1415
        is(
1416
            Koha::Patrons->search_limited->count, 3,
1417
            'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12'
1418
        );
1397
1419
1398
        t::lib::Mocks::mock_userenv({ patron => $patron_21 });
1420
        t::lib::Mocks::mock_userenv( { patron => $patron_21 } );
1399
        $patron_21 = Koha::Patrons->find( $patron_21->borrowernumber );
1421
        $patron_21 = Koha::Patrons->find( $patron_21->borrowernumber );
1400
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons');
1422
        is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' );
1401
        is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' );
1423
        is(
1424
            Koha::Patrons->search_limited->count, 1,
1425
            'patron_21 is not allowed to see patrons from other groups, only himself'
1426
        );
1402
    };
1427
    };
1403
    $patron_11_1->delete;
1428
    $patron_11_1->delete;
1404
    $patron_11_2->delete;
1429
    $patron_11_2->delete;
1405
    $patron_12->delete;
1430
    $patron_12->delete;
1406
    $patron_21->delete;
1431
    $patron_21->delete;
1407
};
1432
    };
1408
1433
1409
subtest 'account_locked' => sub {
1434
subtest 'account_locked' => sub {
1410
    plan tests => 13;
1435
    plan tests => 13;
1411
- 

Return to bug 37378