|
Lines 299-305
subtest 'list_rules() tests' => sub {
Link Here
|
| 299 |
}; |
299 |
}; |
| 300 |
|
300 |
|
| 301 |
subtest 'set_rules() tests' => sub { |
301 |
subtest 'set_rules() tests' => sub { |
| 302 |
plan tests => 28; |
302 |
plan tests => 34; |
| 303 |
|
303 |
|
| 304 |
$schema->storage->txn_begin; |
304 |
$schema->storage->txn_begin; |
| 305 |
|
305 |
|
|
Lines 318-323
subtest 'set_rules() tests' => sub {
Link Here
|
| 318 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
318 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 319 |
my $userid = $librarian->userid; |
319 |
my $userid = $librarian->userid; |
| 320 |
|
320 |
|
|
|
321 |
# Grant manage_circ_rules_from_any_libraries so the librarian can set rules for any library |
| 322 |
$builder->build( |
| 323 |
{ |
| 324 |
source => 'UserPermission', |
| 325 |
value => { |
| 326 |
borrowernumber => $librarian->borrowernumber, |
| 327 |
module_bit => 3, |
| 328 |
code => 'manage_circ_rules_from_any_libraries', |
| 329 |
} |
| 330 |
} |
| 331 |
); |
| 332 |
|
| 321 |
my $patron = $builder->build_object( |
333 |
my $patron = $builder->build_object( |
| 322 |
{ |
334 |
{ |
| 323 |
class => 'Koha::Patrons', |
335 |
class => 'Koha::Patrons', |
|
Lines 328-333
subtest 'set_rules() tests' => sub {
Link Here
|
| 328 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
340 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 329 |
my $unauth_userid = $patron->userid; |
341 |
my $unauth_userid = $patron->userid; |
| 330 |
|
342 |
|
|
|
343 |
# Restricted librarian: has manage_circ_rules but NOT manage_circ_rules_from_any_libraries |
| 344 |
my $own_branch = $builder->build( { source => 'Branch' } )->{'branchcode'}; |
| 345 |
my $other_branch = $builder->build( { source => 'Branch' } )->{'branchcode'}; |
| 346 |
my $restricted_patron = $builder->build_object( |
| 347 |
{ |
| 348 |
class => 'Koha::Patrons', |
| 349 |
value => { flags => 0, branchcode => $own_branch } |
| 350 |
} |
| 351 |
); |
| 352 |
$restricted_patron->set_password( { password => $password, skip_validation => 1 } ); |
| 353 |
my $restricted_userid = $restricted_patron->userid; |
| 354 |
$builder->build( |
| 355 |
{ |
| 356 |
source => 'UserPermission', |
| 357 |
value => { |
| 358 |
borrowernumber => $restricted_patron->borrowernumber, |
| 359 |
module_bit => 3, |
| 360 |
code => 'manage_circ_rules', |
| 361 |
} |
| 362 |
} |
| 363 |
); |
| 364 |
|
| 331 |
## Authorized user tests |
365 |
## Authorized user tests |
| 332 |
note("Authorized user setting rules"); |
366 |
note("Authorized user setting rules"); |
| 333 |
|
367 |
|
|
Lines 416-420
subtest 'set_rules() tests' => sub {
Link Here
|
| 416 |
{ categorycode => undef, branchcode => undef, itemtype => undef, rule_name => 'finedays' } ); |
450 |
{ categorycode => undef, branchcode => undef, itemtype => undef, rule_name => 'finedays' } ); |
| 417 |
is( $rules->count, 0, "Finedays rule deleted from database" ); |
451 |
is( $rules->count, 0, "Finedays rule deleted from database" ); |
| 418 |
|
452 |
|
|
|
453 |
# manage_circ_rules_from_any_libraries restriction tests |
| 454 |
note("Testing manage_circ_rules_from_any_libraries restrictions"); |
| 455 |
|
| 456 |
my $restricted_rules = { |
| 457 |
context => { |
| 458 |
library_id => '*', |
| 459 |
patron_category_id => '*', |
| 460 |
item_type_id => '*', |
| 461 |
}, |
| 462 |
fine => 3, |
| 463 |
}; |
| 464 |
|
| 465 |
$t->put_ok( "//$restricted_userid:$password@/api/v1/circulation_rules" => json => $restricted_rules ) |
| 466 |
->status_is( 403, "Restricted user cannot set rules for default (*) library" ); |
| 467 |
|
| 468 |
$restricted_rules->{context}->{library_id} = $other_branch; |
| 469 |
$t->put_ok( "//$restricted_userid:$password@/api/v1/circulation_rules" => json => $restricted_rules ) |
| 470 |
->status_is( 403, "Restricted user cannot set rules for another library" ); |
| 471 |
|
| 472 |
$restricted_rules->{context}->{library_id} = $own_branch; |
| 473 |
$t->put_ok( "//$restricted_userid:$password@/api/v1/circulation_rules" => json => $restricted_rules ) |
| 474 |
->status_is( 200, "Restricted user can set rules for their own library" ); |
| 475 |
|
| 419 |
$schema->storage->txn_rollback; |
476 |
$schema->storage->txn_rollback; |
| 420 |
}; |
477 |
}; |
| 421 |
- |
|
|