Lines 2416-2422
subtest 'filter_by_amount_owed' => sub {
Link Here
|
2416 |
is( $filtered->_resultset->as_subselect_rs->count, 1, |
2416 |
is( $filtered->_resultset->as_subselect_rs->count, 1, |
2417 |
"filter_by_amount_owed({ more_than => 6.00, library => $library2->{branchcode} }) found one patron" |
2417 |
"filter_by_amount_owed({ more_than => 6.00, library => $library2->{branchcode} }) found one patron" |
2418 |
); |
2418 |
); |
|
|
2419 |
}; |
2420 |
|
2421 |
subtest 'libraries_where_can_edit_items + can_edit_item' => sub { |
2422 |
plan tests => 2; |
2423 |
|
2424 |
$schema->storage->txn_begin; |
2425 |
my $dbh = $schema->storage->dbh; |
2426 |
|
2427 |
$dbh->do("DELETE FROM library_groups"); |
2428 |
|
2429 |
# group1 |
2430 |
# library_1A |
2431 |
# library_1B |
2432 |
# group2 |
2433 |
# library_2A |
2434 |
my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store; |
2435 |
my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store; |
2436 |
my $library_1A = $builder->build( { source => 'Branch' } ); |
2437 |
my $library_1B = $builder->build( { source => 'Branch' } ); |
2438 |
my $library_2A = $builder->build( { source => 'Branch' } ); |
2439 |
$library_1A = Koha::Libraries->find( $library_1A->{branchcode} ); |
2440 |
$library_1B = Koha::Libraries->find( $library_1B->{branchcode} ); |
2441 |
$library_2A = Koha::Libraries->find( $library_2A->{branchcode} ); |
2442 |
Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store; |
2443 |
Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store; |
2444 |
Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store; |
2445 |
|
2446 |
my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue |
2447 |
# 2 patrons from library_1A (group1) |
2448 |
# patron_1A_1 see patron's infos from outside its group |
2449 |
# Setting flags => undef to not be considered as superlibrarian |
2450 |
my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); |
2451 |
$patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} ); |
2452 |
$sth->execute( $patron_1A_1->borrowernumber, 'edit_items' ); |
2453 |
$sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' ); |
2454 |
# patron_1A_2 can only see patron's info from its group |
2455 |
my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); |
2456 |
$patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} ); |
2457 |
$sth->execute( $patron_1A_2->borrowernumber, 'edit_items' ); |
2458 |
# 1 patron from library_1B (group1) |
2459 |
my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }}); |
2460 |
$patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} ); |
2461 |
# 1 patron from library_2A (group2) can only see patron's info from its group |
2462 |
my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }}); |
2463 |
$patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} ); |
2464 |
$sth->execute( $patron_2A->borrowernumber, 'edit_items' ); |
2465 |
|
2466 |
subtest 'libraries_where_can_edit_items' => sub { |
2467 |
plan tests => 3; |
2419 |
|
2468 |
|
|
|
2469 |
my @branchcodes; |
2470 |
|
2471 |
@branchcodes = $patron_1A_1->libraries_where_can_edit_items; |
2472 |
is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" ); |
2473 |
|
2474 |
@branchcodes = $patron_1A_2->libraries_where_can_edit_items; |
2475 |
is_deeply( \@branchcodes, [ sort ( $library_1A->branchcode, $library_1B->branchcode ) ], "patron_1A_2 doesn't have edit_any_item => Can only edit items from its group" ); |
2476 |
|
2477 |
@branchcodes = $patron_2A->libraries_where_can_edit_items; |
2478 |
is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" ); |
2479 |
}; |
2480 |
|
2481 |
subtest 'can_edit_item' => sub { |
2482 |
plan tests => 6; |
2483 |
|
2484 |
t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 }); |
2485 |
is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" ); |
2486 |
is( $patron_1A_1->can_edit_item( $library_1B->id ), 1, "patron_1A_1 can see patron_1B, from its group" ); |
2487 |
is( $patron_1A_1->can_edit_item( $library_2A->id ), 1, "patron_1A_1 can see patron_1A_2, from another group" ); |
2488 |
|
2489 |
t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 }); |
2490 |
is( $patron_1A_2->can_edit_item( $library_1A->id ), 1, "patron_1A_2 can see patron_1A_1, from its library" ); |
2491 |
is( $patron_1A_2->can_edit_item( $library_1B->id ), 1, "patron_1A_2 can see patron_1B, from its group" ); |
2492 |
is( $patron_1A_2->can_edit_item( $library_2A->id ), 0, "patron_1A_2 can NOT see patron_2A, from another group" ); |
2493 |
}; |
2420 |
}; |
2494 |
}; |
2421 |
|
2495 |
|
2422 |
subtest 'filter_by_have_subpermission' => sub { |
2496 |
subtest 'filter_by_have_subpermission' => sub { |
2423 |
- |
|
|