TT#130456 API Customers POST: show error if system template

Throw descriptive error for attempt to create Customer with Template
that does not belong to Contact’s Reseller. Cover the case when the
Template belongs to System Contact (with no Reseller).

Error example:
'subscriber_email_template_id' with value '1' does not belong to
Reseller '1' that is assigned to Customer's Contact '1'

Change-Id: Iffcef0339afc4490ecba81d4667cbb9225766af4
mr10.1
Victor Tsvetov 5 years ago
parent 35e9b4ecc9
commit 3cb71e4ceb

@ -268,13 +268,18 @@ sub POST :Allow {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "The contact_id is not a valid ngcp:customercontacts item, but an ngcp:systemcontacts item");
last;
}
#todo: strange: why do we check this after customer creation?
my $tmplfields = $self->get_template_fields_spec();
foreach my $field (keys %$tmplfields){
next unless $customer->$field();
my $field_table_rel = $tmplfields->{$field}->[1];
if($customer->$field() &&
$customer->$field_table_rel()->reseller_id != $customer->contact->reseller_id) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid '$field', doesn't exist for the reseller assigned to customer contact");
unless($customer->$field_table_rel()->reseller_id &&
$customer->$field_table_rel()->reseller_id == $customer->contact->reseller_id) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "'$field' with value '" . $customer->$field()
. "' does not belong to Reseller '" . $customer->contact->reseller_id
. "' that is assigned to Customer's Contact '$resource->{contact_id}'");
return;
}
}

Loading…
Cancel
Save