Bug 37256: Ensure empty and null work as expected in PUT
Sponsored-by: Glasgow Colleges Library Group <https://library.cityofglasgowcollege.ac.uk> Signed-off-by: George Harkins <George.Harkins@cityofglasgowcollege.ac.uk> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
adae95debe
commit
e5eaa2aa17
|
|
@ -96,10 +96,6 @@ our $RULE_KINDS = {
|
|||
cap_fine_to_replacement_price => {
|
||||
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
|
||||
},
|
||||
expire_reserves_charge => {
|
||||
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
|
||||
can_be_blank => 0,
|
||||
},
|
||||
chargeperiod => {
|
||||
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
|
||||
},
|
||||
|
|
@ -416,6 +412,7 @@ sub set_rule {
|
|||
$rule->rule_value($rule_value);
|
||||
$rule->update();
|
||||
} else {
|
||||
$rule->rule_value(undef);
|
||||
$rule->delete();
|
||||
}
|
||||
} else {
|
||||
|
|
@ -438,6 +435,10 @@ sub set_rule {
|
|||
$memory_cache->clear_from_cache($k) if $k =~ m{^CircRules:};
|
||||
}
|
||||
|
||||
$rule = Koha::CirculationRule->new(
|
||||
{ rule_name => $rule_name, branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype } )
|
||||
unless $rule;
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
|
|
@ -753,37 +754,6 @@ sub get_effective_daysmode {
|
|||
|
||||
}
|
||||
|
||||
=head3 get_effective_expire_reserves_charge
|
||||
|
||||
Return the value for expire_reserves_charge defined in the circulation rules.
|
||||
If not defined (or empty string), the value of the system preference ExpireReservesMaxPickUpDelayCharge is returned
|
||||
|
||||
=cut
|
||||
|
||||
sub get_effective_expire_reserves_charge {
|
||||
my ( $class, $params ) = @_;
|
||||
|
||||
my $itemtype = $params->{itemtype};
|
||||
my $branchcode = $params->{branchcode};
|
||||
my $categorycode = $params->{categorycode};
|
||||
|
||||
my $expire_reserves_charge_rule = $class->get_effective_rule(
|
||||
{
|
||||
itemtype => $itemtype,
|
||||
branchcode => $branchcode,
|
||||
categorycode => $categorycode,
|
||||
rule_name => 'expire_reserves_charge',
|
||||
}
|
||||
);
|
||||
|
||||
# return the rule value (incl. 0) if rule found so there's an object in the variable,
|
||||
# or return default value from sysprefs when rule wasn't found and there's undef
|
||||
return $expire_reserves_charge_rule
|
||||
? $expire_reserves_charge_rule->rule_value
|
||||
: C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
|
||||
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ subtest 'list_rules() tests' => sub {
|
|||
};
|
||||
|
||||
subtest 'set_rules() tests' => sub {
|
||||
plan tests => 23;
|
||||
plan tests => 28;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -388,5 +388,21 @@ subtest 'set_rules() tests' => sub {
|
|||
is( $json->{fine}, 10, "Fine rule set correctly for wildcard context" );
|
||||
is( $json->{finedays}, 7, "Finedays rule set correctly for wildcard context" );
|
||||
|
||||
# Setting rules empty and undefined
|
||||
note("Setting rules to empty and undefined");
|
||||
$rules_to_set->{fine} = '';
|
||||
$rules_to_set->{finedays} = undef;
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(200);
|
||||
|
||||
# Verify the rules were updated
|
||||
$json = $t->tx->res->json;
|
||||
is( $json->{fine}, '', "Fine rule updated correctly" );
|
||||
is( $json->{finedays}, undef, "Finedays rule remains the same" );
|
||||
|
||||
# Verify that the explicit undef results in a rule deletion
|
||||
my $rules = Koha::CirculationRules->search(
|
||||
{ categorycode => undef, branchcode => undef, itemtype => undef, rule_name => 'finedays' } );
|
||||
is( $rules->count, 0, "Finedays rule deleted from database" );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue