diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 412cb58f6e..f67e2bb72e 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -127,8 +127,19 @@ sub validate_form { } } - # remove unknown keys - my %fields = map { $_->name => $_ } $form->fields; + # remove unknown keys and prepare resource + my %fields; + foreach($form->fields){ + if($_->readonly){ + #Prepare resource for the PATCH considering readonly fields. + #PATCH is supposed to take full item content and so will get readonly fields into resource too. And apply patch. + #It leads to the situation when we may try to change some not existing fields in the DB + #All readonly fields are considered as representation only and should never be applied. + delete $resource->{$_->name}; + next; + } + $fields{$_->name} = $_; + } $self->validate_fields($c, $resource, \%fields, $run); if($run) { diff --git a/t/api-rest/api-customers-collection.t b/t/api-rest/api-customers-collection.t index 8088fba0bd..05ad3db80a 100644 --- a/t/api-rest/api-customers-collection.t +++ b/t/api-rest/api-customers-collection.t @@ -56,6 +56,13 @@ SKIP:{ #todo: create_timestamp - strange, it is different to the value of the time zone $test_machine->check_get2put({ignore_fields => [qw/modify_timestamp create_timestamp/]}); + my $mod_customer; + ($res,$mod_customer) = $test_machine->check_patch_correct( [ { op => 'replace', path => '/subscriber_email_template_id', value => undef } ] ); + is($mod_customer->{subscriber_email_template_id}, undef, "check patched subscriber_email_template_id:".($mod_customer->{subscriber_email_template_id} // 'undef')); + + ($res,$mod_customer) = $test_machine->check_patch_correct( [ { op => 'replace', path => '/subscriber_email_template_id', value => $test_machine->DATA_ITEM->{subscriber_email_template_id} } ] ); + is($mod_customer->{subscriber_email_template_id}, $test_machine->DATA_ITEM->{subscriber_email_template_id}, "check patched subscriber_email_template_id:".$mod_customer->{subscriber_email_template_id}); + $test_machine->check_bundle(); }