Lines 1284-1292
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' => |
1287 |
subtest |
1288 |
sub { |
1288 |
'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited+ can_see_patrons_from + can_edit_items_from' |
1289 |
plan tests => 4; |
1289 |
=> sub { |
|
|
1290 |
plan tests => 6; |
1290 |
|
1291 |
|
1291 |
# group1 |
1292 |
# group1 |
1292 |
# + library_11 |
1293 |
# + library_11 |
Lines 1299-1328
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_
Link Here
|
1299 |
my $library_11 = $builder->build( { source => 'Branch' } ); |
1300 |
my $library_11 = $builder->build( { source => 'Branch' } ); |
1300 |
my $library_12 = $builder->build( { source => 'Branch' } ); |
1301 |
my $library_12 = $builder->build( { source => 'Branch' } ); |
1301 |
my $library_21 = $builder->build( { source => 'Branch' } ); |
1302 |
my $library_21 = $builder->build( { source => 'Branch' } ); |
|
|
1303 |
my $library_31 = $builder->build( { source => 'Branch' } ); |
1302 |
$library_11 = Koha::Libraries->find( $library_11->{branchcode} ); |
1304 |
$library_11 = Koha::Libraries->find( $library_11->{branchcode} ); |
1303 |
$library_12 = Koha::Libraries->find( $library_12->{branchcode} ); |
1305 |
$library_12 = Koha::Libraries->find( $library_12->{branchcode} ); |
1304 |
$library_21 = Koha::Libraries->find( $library_21->{branchcode} ); |
1306 |
$library_21 = Koha::Libraries->find( $library_21->{branchcode} ); |
|
|
1307 |
$library_31 = Koha::Libraries->find( $library_31->{branchcode} ); |
1305 |
Koha::Library::Group->new( { branchcode => $library_11->branchcode, parent_id => $group_1->id } )->store; |
1308 |
Koha::Library::Group->new( { 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; |
1309 |
Koha::Library::Group->new( { branchcode => $library_12->branchcode, parent_id => $group_1->id } )->store; |
1307 |
Koha::Library::Group->new( { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store; |
1310 |
Koha::Library::Group->new( { branchcode => $library_21->branchcode, parent_id => $group_2->id } )->store; |
|
|
1311 |
# Library 31, not in any group |
1308 |
|
1312 |
|
1309 |
my $sth = |
1313 |
my $sth = |
1310 |
C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 4, ?)|) |
1314 |
C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, ?, ?)|); |
1311 |
; # 4 for borrowers |
1315 |
|
1312 |
# 2 patrons from library_11 (group1) |
1316 |
# 2 patrons from library_11 (group1) |
1313 |
# patron_11_1 see patron's infos from outside its group |
1317 |
# patron_11_1 see patron's infos from outside its group |
1314 |
# Setting flags => undef to not be considered as superlibrarian |
1318 |
# Setting flags => undef to not be considered as superlibrarian |
1315 |
my $patron_11_1 = $builder->build( |
1319 |
my $patron_11_1 = $builder->build( |
1316 |
{ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } ); |
1320 |
{ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } ); |
1317 |
$patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} ); |
1321 |
$patron_11_1 = Koha::Patrons->find( $patron_11_1->{borrowernumber} ); |
1318 |
$sth->execute( $patron_11_1->borrowernumber, 'edit_borrowers' ); |
1322 |
$sth->execute( $patron_11_1->borrowernumber, 4, 'edit_borrowers' ); |
1319 |
$sth->execute( $patron_11_1->borrowernumber, 'view_borrower_infos_from_any_libraries' ); |
1323 |
$sth->execute( $patron_11_1->borrowernumber, 4, 'view_borrower_infos_from_any_libraries' ); |
1320 |
|
1324 |
|
1321 |
# patron_11_2 can only see patron's info from its group |
1325 |
# patron_11_2 can only see patron's info from its group |
1322 |
my $patron_11_2 = $builder->build( |
1326 |
my $patron_11_2 = $builder->build( |
1323 |
{ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } ); |
1327 |
{ source => 'Borrower', value => { branchcode => $library_11->branchcode, flags => undef, } } ); |
1324 |
$patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} ); |
1328 |
$patron_11_2 = Koha::Patrons->find( $patron_11_2->{borrowernumber} ); |
1325 |
$sth->execute( $patron_11_2->borrowernumber, 'edit_borrowers' ); |
1329 |
$sth->execute( $patron_11_2->borrowernumber, 4, 'edit_borrowers' ); |
|
|
1330 |
$sth->execute( $patron_11_2->borrowernumber, 9, 'edit_items' ); |
1326 |
|
1331 |
|
1327 |
# 1 patron from library_12 (group1) |
1332 |
# 1 patron from library_12 (group1) |
1328 |
my $patron_12 = $builder->build( |
1333 |
my $patron_12 = $builder->build( |
Lines 1333-1363
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_
Link Here
|
1333 |
my $patron_21 = $builder->build( |
1338 |
my $patron_21 = $builder->build( |
1334 |
{ source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, } } ); |
1339 |
{ source => 'Borrower', value => { branchcode => $library_21->branchcode, flags => undef, } } ); |
1335 |
$patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} ); |
1340 |
$patron_21 = Koha::Patrons->find( $patron_21->{borrowernumber} ); |
1336 |
$sth->execute( $patron_21->borrowernumber, 'edit_borrowers' ); |
1341 |
$sth->execute( $patron_21->borrowernumber, 4, 'edit_borrowers' ); |
|
|
1342 |
|
1343 |
# 1 patron from library_31 (no group) can only see patron's info from its library |
1344 |
my $patron_31 = $builder->build( |
1345 |
{ source => 'Borrower', value => { branchcode => $library_31->branchcode, flags => undef, } } ); |
1346 |
$patron_31 = Koha::Patrons->find( $patron_31->{borrowernumber} ); |
1347 |
$sth->execute( $patron_31->borrowernumber, 4, 'edit_borrowers' ); |
1337 |
|
1348 |
|
1338 |
# Pfiou, we can start now! |
1349 |
# Pfiou, we can start now! |
1339 |
subtest 'libraries_where_can_see_things' => sub { |
1350 |
subtest 'libraries_where_can_see_things' => sub { |
1340 |
plan tests => 2; |
1351 |
plan tests => 4; |
1341 |
t::lib::Mocks::mock_userenv( { patron => $patron_11_2 } ); |
1352 |
t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } ); |
1342 |
my $params = { |
1353 |
my $params = { |
1343 |
permission => 'editcatalogue', |
1354 |
permission => 'borrowers', |
1344 |
subpermission => 'edit_any_item', |
1355 |
subpermission => 'view_borrower_infos_from_any_libraries', |
1345 |
group_feature => 'ft_limit_item_editing', |
1356 |
group_feature => 'ft_hide_patron_info', |
1346 |
}; |
1357 |
}; |
1347 |
my @branchcodes = $patron_11_2->libraries_where_can_see_things($params); |
1358 |
my @branchcodes = $patron_11_1->libraries_where_can_see_things($params); |
1348 |
is_deeply( |
1359 |
is_deeply( |
1349 |
\@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], |
1360 |
\@branchcodes, [], |
1350 |
q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| |
1361 |
q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| |
1351 |
); |
1362 |
); |
|
|
1363 |
@branchcodes = $patron_11_1->libraries_where_can_see_things($params); |
1364 |
is_deeply( |
1365 |
\@branchcodes, [], |
1366 |
q|confirming second/cached request is the same patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| |
1367 |
); |
1368 |
|
1352 |
@branchcodes = $patron_11_2->libraries_where_can_see_things($params); |
1369 |
@branchcodes = $patron_11_2->libraries_where_can_see_things($params); |
1353 |
is_deeply( |
1370 |
is_deeply( |
1354 |
\@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], |
1371 |
\@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], |
1355 |
q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| |
1372 |
q|patron_11_2 can only view from group| |
|
|
1373 |
); |
1374 |
@branchcodes = $patron_11_2->libraries_where_can_see_things($params); |
1375 |
is_deeply( |
1376 |
\@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], |
1377 |
q|confirming second/cached request is the same patron_11_2 can only view from group| |
1356 |
); |
1378 |
); |
1357 |
}; |
1379 |
}; |
1358 |
|
1380 |
|
|
|
1381 |
subtest 'can_see_patrons_from' => sub { |
1382 |
plan tests => 2; |
1383 |
ok( $patron_11_2->can_see_patrons_from( $library_11->branchcode ), "We can see a patron from in our group" ); |
1384 |
ok( |
1385 |
!$patron_11_2->can_see_patrons_from( $library_21->branchcode ), |
1386 |
"We cannot see a patron from outside our group without permissions" |
1387 |
); |
1388 |
}; |
1389 |
|
1390 |
subtest 'can_edit_items_from' => sub { |
1391 |
plan tests => 4; |
1392 |
ok( $patron_11_2->can_edit_items_from( $library_11->branchcode ), "We can edit an item from in our group" ); |
1393 |
ok( |
1394 |
$patron_11_2->can_edit_items_from( $library_21->branchcode ), |
1395 |
"We can edit an item from outside our group as the group does not limit item editing" |
1396 |
); |
1397 |
$group_1->ft_limit_item_editing(1)->store(); |
1398 |
|
1399 |
$patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber ); |
1400 |
|
1401 |
#FIXME We refetch the patron because library lists are cached in an extra hash key |
1402 |
# in libraries_where_can_see_things |
1403 |
|
1404 |
ok( |
1405 |
!$patron_11_2->can_edit_items_from( $library_21->branchcode ), |
1406 |
"We can not edit an item from outside our group as the group does limit item editing" |
1407 |
); |
1408 |
|
1409 |
$sth->execute( $patron_11_2->borrowernumber, 9, 'edit_any_item' ); |
1410 |
$patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber ); |
1411 |
|
1412 |
ok( |
1413 |
$patron_11_2->can_edit_items_from( $library_21->branchcode ), |
1414 |
"We can edit an item from outside our group as we have permission" |
1415 |
); |
1416 |
|
1417 |
}; |
1418 |
|
1359 |
subtest 'libraries_where_can_see_patrons' => sub { |
1419 |
subtest 'libraries_where_can_see_patrons' => sub { |
1360 |
plan tests => 3; |
1420 |
plan tests => 4; |
1361 |
|
1421 |
|
1362 |
my @branchcodes; |
1422 |
my @branchcodes; |
1363 |
|
1423 |
|
Lines 1378-1383
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_
Link Here
|
1378 |
\@branchcodes, [ $library_21->branchcode ], |
1438 |
\@branchcodes, [ $library_21->branchcode ], |
1379 |
q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| |
1439 |
q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| |
1380 |
); |
1440 |
); |
|
|
1441 |
|
1442 |
t::lib::Mocks::mock_userenv( { patron => $patron_31 } ); |
1443 |
@branchcodes = $patron_31->libraries_where_can_see_patrons; |
1444 |
is_deeply( |
1445 |
\@branchcodes, [ $library_31->branchcode ], |
1446 |
q|patron_31 has not view_borrower_infos_from_any_libraries => Can only see patron's from its library that is not in a group| |
1447 |
); |
1381 |
}; |
1448 |
}; |
1382 |
subtest 'can_see_patron_infos' => sub { |
1449 |
subtest 'can_see_patron_infos' => sub { |
1383 |
plan tests => 6; |
1450 |
plan tests => 6; |
Lines 1402-1408
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_
Link Here
|
1402 |
|
1469 |
|
1403 |
t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } ); |
1470 |
t::lib::Mocks::mock_userenv( { patron => $patron_11_1 } ); |
1404 |
$patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber ); |
1471 |
$patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber ); |
1405 |
my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests |
1472 |
my $total_number_of_patrons = $nb_of_patrons + 5; #we added five in these tests |
1406 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' ); |
1473 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' ); |
1407 |
is( |
1474 |
is( |
1408 |
Koha::Patrons->search_limited->count, $total_number_of_patrons, |
1475 |
Koha::Patrons->search_limited->count, $total_number_of_patrons, |
Lines 1429-1434
subtest 'libraries_where_can_see_patrons + libraries_where_can_see_things + can_
Link Here
|
1429 |
$patron_11_2->delete; |
1496 |
$patron_11_2->delete; |
1430 |
$patron_12->delete; |
1497 |
$patron_12->delete; |
1431 |
$patron_21->delete; |
1498 |
$patron_21->delete; |
|
|
1499 |
$patron_31->delete; |
1432 |
}; |
1500 |
}; |
1433 |
|
1501 |
|
1434 |
subtest 'account_locked' => sub { |
1502 |
subtest 'account_locked' => sub { |