TT#33399 Make owner a mandatory parameter for the conversations API

* Owner data checked and stored in stash to avoid multiply checking in list context

Change-Id: Ie5663ccc1c7385f25f8ff989b1f52a9b74a5ba2d
changes/27/19427/9
Irina Peshinskaya 7 years ago
parent 272e658628
commit fea5aa71af

@ -211,8 +211,7 @@ sub get_list{
#TODO: move to config and return to the SUPER (Entities) again #TODO: move to config and return to the SUPER (Entities) again
#So: if config->{methtod}->{required_params} eq '' owner #So: if config->{methtod}->{required_params} eq '' owner
#and for other types of possible required parameters or predefined parameters groups #and for other types of possible required parameters or predefined parameters groups
my $schema = $c->model('DB'); my $owner = $self->get_owner_cached($c);
my $owner = NGCP::Panel::Utils::API::Calllist::get_owner_data($self, $c, $schema);
unless (defined $owner) { unless (defined $owner) {
return; return;
} }
@ -241,8 +240,15 @@ sub get_item_id{
$type = $item->type; $type = $item->type;
} }
if(('HASH' eq ref $params) && 'hal_links_href' eq $params->{purpose}){ if(('HASH' eq ref $params) && 'hal_links_href' eq $params->{purpose}){
return $id.'?type='.$type; my $owner = $self->get_owner_cached( $c);
return unless $owner;
return $id.'?type='.$type
.($owner->{subscriber}
? '&subscriber_id='.$owner->{subscriber}->id
: ( $owner->{customer} )
? '&customer_id='.$owner->{customer}->id
: ''
);
} }
return $id ; return $id ;
} }
@ -748,20 +754,18 @@ sub process_hal_resource {
$c->log->debug(Dumper($item)); $c->log->debug(Dumper($item));
my ($item_mock_obj, $item_accessors_hash) = _get_item_object($c, $item); my ($item_mock_obj, $item_accessors_hash) = _get_item_object($c, $item);
if('call' eq $item->{type}){ if('call' eq $item->{type}){
my $cdr_subscriber_id = $c->model('DB')->resultset('voip_subscribers')->search_rs({ my $owner = $self->get_owner_cached($c);
'uuid' => $item_mock_obj->source_user_id, return unless $owner;
})->first->id;
my $cdr_customer_id = $item_mock_obj->source_account_id;
my $owner = NGCP::Panel::Utils::API::Calllist::get_owner_data($self, $c, $schema, { subscriber_id => $cdr_subscriber_id } );
if(!$owner){
return;
}
$resource = NGCP::Panel::Utils::CallList::process_cdr_item( $resource = NGCP::Panel::Utils::CallList::process_cdr_item(
$c, $c,
$item_mock_obj, $item_mock_obj,
$owner, $owner,
); );
@{$resource}{qw/caller callee/} = @{$resource}{qw/own_cli other_cli/}; if ("out" eq $resource->{direction}) {
@{$resource}{qw/caller callee/} = @{$resource}{qw/own_cli other_cli/};
} else {
@{$resource}{qw/caller callee/} = @{$resource}{qw/other_cli own_cli/};
}
$resource->{type} = $item->{type}; $resource->{type} = $item->{type};
my $fee; my $fee;
if ($fee = $schema->resultset('billing_fees_history')->search_rs({ if ($fee = $schema->resultset('billing_fees_history')->search_rs({
@ -822,6 +826,19 @@ sub process_hal_resource {
return $resource; return $resource;
} }
sub get_owner_cached{
my ($self, $c) = @_;
my $schema = $c->model('DB');
if ( ! $c->stash->{owner} ) {
my $source;
if ($c->req->params->{customer_id} or $c->req->params->{subscriber_id}) {
$source = $c->req->params;
}
$c->stash->{owner} = NGCP::Panel::Utils::API::Calllist::get_owner_data($self, $c, $schema, $source);
}
return $c->stash->{owner};
}
sub _get_fields_names{ sub _get_fields_names{
my ($fields, $fields_tied) = @_; my ($fields, $fields_tied) = @_;
return { map { $_ => $fields_tied->Indices($_) ? _get_alias($fields_tied->Indices($_) + 1) : $_; } (keys %$fields, 'id','type','timestamp') }; return { map { $_ => $fields_tied->Indices($_) ? _get_alias($fields_tied->Indices($_) + 1) : $_; } (keys %$fields, 'id','type','timestamp') };

Loading…
Cancel
Save