diff --git a/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm b/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm index 475d02e5f3..cf594766a1 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm @@ -154,11 +154,15 @@ sub POST :Allow { last unless $txn_ok; $item = $self->fetch_item($c, $resource, $form, $item); - last unless $item; - $c->response->status(HTTP_CREATED); - $c->response->header(Location => sprintf('/%s%s', $c->request->path, $item->id)); - $c->response->body(q()); + if ($item) { + $c->response->status(HTTP_CREATED); + $c->response->header(Location => sprintf('/%s%s', $c->request->path, $item->id)); + $c->response->body(q()); + } else { + $c->response->status(HTTP_CREATED); + $c->response->body(q()); + } } return; } diff --git a/lib/NGCP/Panel/Controller/API/SubscriberRegistrationsItem.pm b/lib/NGCP/Panel/Controller/API/SubscriberRegistrationsItem.pm index 7fa21b7b00..d7bd82c6cc 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberRegistrationsItem.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberRegistrationsItem.pm @@ -96,22 +96,26 @@ sub PATCH :Allow { last unless $txn_ok; $item = $self->fetch_item($c, $resource, $form, $item); - last unless $item; - if ('minimal' eq $preference) { - $c->response->status(HTTP_NO_CONTENT); - $c->response->header(Preference_Applied => 'return=minimal'); - $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); - $c->response->body(q()); + if ($item) { + if ('minimal' eq $preference) { + $c->response->status(HTTP_NO_CONTENT); + $c->response->header(Preference_Applied => 'return=minimal'); + $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); + $c->response->body(q()); + } else { + my $hal = $self->hal_from_item($c, $item, $form); + my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( + $hal->http_headers, + ), $hal->as_json); + $c->response->headers($response->headers); + $c->response->header(Preference_Applied => 'return=representation'); + $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); + $c->response->body($response->content); + } } else { - my $hal = $self->hal_from_item($c, $item, $form); - my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( - $hal->http_headers, - ), $hal->as_json); - $c->response->headers($response->headers); - $c->response->header(Preference_Applied => 'return=representation'); - $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); - $c->response->body($response->content); + $c->response->status(HTTP_NO_CONTENT); + $c->response->body(q()); } } @@ -152,22 +156,26 @@ sub PUT :Allow { last unless $txn_ok; $item = $self->fetch_item($c, $resource, $form, $item); - last unless $item; - if ('minimal' eq $preference) { - $c->response->status(HTTP_NO_CONTENT); - $c->response->header(Preference_Applied => 'return=minimal'); - $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); - $c->response->body(q()); + if ($item) { + if ('minimal' eq $preference) { + $c->response->status(HTTP_NO_CONTENT); + $c->response->header(Preference_Applied => 'return=minimal'); + $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); + $c->response->body(q()); + } else { + my $hal = $self->hal_from_item($c, $item, $form); + my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( + $hal->http_headers, + ), $hal->as_json); + $c->response->headers($response->headers); + $c->response->header(Preference_Applied => 'return=representation'); + $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); + $c->response->body($response->content); + } } else { - my $hal = $self->hal_from_item($c, $item, $form); - my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( - $hal->http_headers, - ), $hal->as_json); - $c->response->headers($response->headers); - $c->response->header(Preference_Applied => 'return=representation'); - $c->response->header(Location => sprintf('%s%s', $self->dispatch_path, $item->id)); - $c->response->body($response->content); + $c->response->status(HTTP_NO_CONTENT); + $c->response->body(q()); } } @@ -195,7 +203,7 @@ sub delete_item { return unless($sub); NGCP::Panel::Utils::Kamailio::delete_location_contact($c, $sub, $item->contact); - NGCP::Panel::Utils::Kamailio::flush($c); + NGCP::Panel::Utils::Kamailio::flush($c) unless $self->suppress_flush($c); return 1; } diff --git a/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm b/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm index 43f68df91e..17457d682c 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm @@ -229,7 +229,7 @@ sub update_item { $sub->provisioning_voip_subscriber, $values ); - NGCP::Panel::Utils::Kamailio::flush($c); + NGCP::Panel::Utils::Kamailio::flush($c) unless $self->suppress_flush($c); return $item; } @@ -270,6 +270,19 @@ sub fetch_item { return $item; } +sub suppress_flush { + + my ($self, $c) = @_; + my $suppress_flush = $c->req->param('suppress_flush'); + if (length($suppress_flush) + and ('1' eq $suppress_flush + or 'true' eq lc($suppress_flush))) { + return 1; + } + return 0; + +} + sub valid_id { my ($self, $id) = @_; if (defined $id && length $id > 0) {