MT#60197 support deleting call recordings per subscriber

admin panel will no longer delete callrecordings for
all parties of the call, but the single subscriber only.

rest-api, behaves the same way, if the ?subscriber_id=
parameter is provided.

when a callrecording is deleted by all call parties,
the remaining records and recording files will be
dropped.

Change-Id: I61f667bdb074a935a8a04473a3685b10e5e09222
(cherry picked from commit 1c09e2773a)
mr11.5
Rene Krenn 6 months ago
parent 83d2eca316
commit 22c5b8ad7e

@ -32,7 +32,7 @@ sub query_params {
{
# we handle that separately/manually in the role
param => 'subscriber_id',
description => 'Filter for callrecordings where the subscriber with the given id is involved.',
description => 'Filter callrecordings for or delete callrecording of the given subscriber_id only.',
},
{
# we handle that separately/manually in the role

@ -3,6 +3,10 @@ use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
sub allowed_methods{
return [qw/GET OPTIONS HEAD DELETE/];
}
use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::CallRecordings/;
use NGCP::Panel::Utils::Subscriber;
@ -12,25 +16,38 @@ __PACKAGE__->set_config({
allowed_roles => [qw/admin reseller subscriberadmin subscriber/],
});
sub allowed_methods{
return [qw/GET OPTIONS HEAD DELETE/];
}
sub DELETE :Allow {
my ($self, $c, $id) = @_;
$c->model('DB')->set_transaction_isolation('READ COMMITTED');
my $guard = $c->model('DB')->txn_scope_guard;
{
my $recording = $self->item_by_id($c, $id);
last unless $self->resource_exists($c, callrecording => $recording);
my $subs;
$subs = $c->model('DB')->resultset('voip_subscribers')->search({
id => $c->req->params->{subscriber_id}
})->first if $c->req->params->{subscriber_id};
try {
NGCP::Panel::Utils::Subscriber::delete_callrecording(
c => $c,
recording => $recording,
force_delete => $c->request->params->{force_delete},
uuid => ($subs ? $subs->uuid : undef),
);
} catch($e) {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to delete callrecording.", $e);
last;
}
$guard->commit;
$c->response->status(HTTP_NO_CONTENT);
$c->response->body(q());
sub delete_item {
my ($self, $c, $item) = @_;
try {
NGCP::Panel::Utils::Subscriber::delete_callrecording(
c => $c,
recording => $item,
#TODO: Now we don't use any way to document such parameters, need to be created
force_delete => $c->request->params->{force_delete},
);
} catch($e) {
$c->log->error("failed to delete callrecording: $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to delete callrecording.");
return;
}
return 1;
return;
}
1;

@ -4430,7 +4430,8 @@ sub delete_recording :Chained('recording') :PathPart('delete') :Args(0) {
NGCP::Panel::Utils::Subscriber::delete_callrecording(
c => $c,
recording => $recording,
force_delete => $form->values->{force_delete}
force_delete => $form->values->{force_delete},
uuid => $c->stash->{subscriber}->uuid,
);
});
NGCP::Panel::Utils::Message::info(

@ -2522,23 +2522,43 @@ sub get_voicemail_content_type {
sub delete_callrecording {
my %params = @_;
my($recording, $force_delete) = @params{qw/recording force_delete/};
my($c,$recording, $force_delete, $uuid) = @params{qw/c recording force_delete uuid/};
foreach my $stream($recording->recording_streams->all) {
#if we met some error deleting file - we will fail and transaction will be rollbacked
if (! -e $stream->full_filename && !$force_delete) {
die "Callrecording file ".$stream->full_filename." is absent";
$recording = $c->model('DB')->resultset('recording_calls')->find({
id => $recording->id
},{for => 'update'});
my $delete_all = 1;
if ($uuid) {
$recording->recording_metakeys->search_rs({
'key' => 'uuid',
'value' => $uuid,
})->delete;
if ($recording->recording_metakeys->search_rs({
'key' => 'uuid',
})->first) {
$delete_all = 0;
}
eval {
unlink $stream->full_filename;
};
if ($@ && !$force_delete) {
die("Cannot delete call recording file: $@");
}
if ($delete_all) {
foreach my $stream($recording->recording_streams->all) {
#if we met some error deleting file - we will fail and transaction will be rollbacked
if (! -e $stream->full_filename && !$force_delete) {
die "Callrecording file ".$stream->full_filename." is absent";
}
eval {
unlink $stream->full_filename;
};
if ($@ && !$force_delete) {
die("Cannot delete call recording file: $@");
}
}
$recording->recording_metakeys->delete;
$recording->recording_streams->delete;
$recording->delete;
}
$recording->recording_streams->delete;
$recording->recording_metakeys->delete;
$recording->delete;
}
sub prov_to_billing_subscriber_id {

Loading…
Cancel
Save