From 1872f342a0ab506c1ab7cc76ab068f088f0d745f Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 4 Apr 2024 16:27:49 +0200 Subject: [PATCH] MT#59478 Entities/EntitiesItem more $c->has_errors checks * additional $c->has_errors checks for post/patch/put/delete to cover all possible expected called inherited methods scenarios and returns. Change-Id: I0e09ba62bcaa51d582315d9cbb672a4cf11bacf0 --- lib/NGCP/Panel/Role/Entities.pm | 15 +++++++++++++++ lib/NGCP/Panel/Role/EntitiesItem.pm | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/NGCP/Panel/Role/Entities.pm b/lib/NGCP/Panel/Role/Entities.pm index 8cf67a07c3..17632b6530 100644 --- a/lib/NGCP/Panel/Role/Entities.pm +++ b/lib/NGCP/Panel/Role/Entities.pm @@ -287,24 +287,36 @@ sub post { ); unless ($self->process_form_resource($c, undef, undef, $resource, $form, $process_extras)) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_UNPROCESSABLE_ENTITY, 'Could not validate request data', '#pre_process_form_resource') unless $c->has_errors; goto TX_END; } unless ($self->check_duplicate($c, undef, undef, $resource, $form, $process_extras)) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_UNPROCESSABLE_ENTITY, 'Could not validate request data', '#check_duplicates') unless $c->has_errors; goto TX_END; } unless ($self->check_resource($c, undef, undef, $resource, $form, $process_extras)) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_UNPROCESSABLE_ENTITY, 'Could not validate request data', '#check_resource') unless $c->has_errors; goto TX_END; } $item = $self->create_item($c, $resource, $form, $process_extras); + if ($c->has_errors) { + goto TX_END; + } unless ($item || $self->get_config('no_item_created')) { $self->error($c, HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error', '#create_item') unless $c->has_errors; @@ -313,6 +325,9 @@ sub post { ($hal, $hal_id) = $self->get_journal_item_hal($c, $item, { form => $form }); unless ($self->add_journal_item_hal($c, { hal => $hal, ($hal_id ? ( id => $hal_id, ) : ()) })) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error', '#add_journal_item_hal') unless $c->has_errors; goto TX_END; diff --git a/lib/NGCP/Panel/Role/EntitiesItem.pm b/lib/NGCP/Panel/Role/EntitiesItem.pm index 900865aac9..ca9bbee331 100644 --- a/lib/NGCP/Panel/Role/EntitiesItem.pm +++ b/lib/NGCP/Panel/Role/EntitiesItem.pm @@ -315,6 +315,9 @@ sub patch { ($hal, $hal_id) = $self->get_journal_item_hal($c, $item, { form => $form }); unless ($self->add_journal_item_hal($c, { hal => $hal, ($hal_id ? ( id => $hal_id, ) : ()) })) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error', '#add_journal_item_hal') unless $c->has_errors; goto TX_END; @@ -426,6 +429,9 @@ sub put { ($hal, $hal_id) = $self->get_journal_item_hal($c, $item, { form => $form }); unless ($self->add_journal_item_hal($c, { hal => $hal, ($hal_id ? ( id => $hal_id, ) : ()) })) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error', '#add_journal_item_hal') unless $c->has_errors; goto TX_END; @@ -480,6 +486,9 @@ sub delete { ## no critic (ProhibitBuiltinHomonyms) ($hal, $hal_id) = $self->get_journal_item_hal($c, $item); if ($self->delete_item($c, $item)) { unless ($self->add_journal_item_hal($c, { hal => $hal, ($hal_id ? ( id => $hal_id, ) : ()) })) { + if ($c->has_errors) { + goto TX_END; + } $self->error($c, HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error', '#add_journal_item_hal'); goto TX_END;