From f612ad54d8408cbbcc64a8ceb8f7fa06cf5d16c2 Mon Sep 17 00:00:00 2001
From: Rene Krenn <rkrenn@sipwise.com>
Date: Wed, 13 Nov 2024 11:58:14 +0100
Subject: [PATCH] MT#61513 prevent duplicates in GET /api/callrecordings

callrecording metakeys such as "uuid" for the involved
call party is present multiple times by nature. the
?subscriber_id= query param will then narrow down the
result. alongside an implicit role filtering
(reseller/subscriber), the sql join and filtering for
the uuid key is present 2 times however, and multiplied
records slip through.

this can be prevented with DISTINCT. to avoid performance
impacts and consider other metakeys orrcuring multiple
times, it will be applied only if a filter is present.

Change-Id: I08047aaee265e2e0a706220e03fd4617da16d33c
(cherry picked from commit 598f7dbaf4e0f2414daf478a2bba52178d433c6a)
---
 lib/NGCP/Panel/Role/API/CallRecordings.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/NGCP/Panel/Role/API/CallRecordings.pm b/lib/NGCP/Panel/Role/API/CallRecordings.pm
index 0df8e47163..0859c21fcb 100644
--- a/lib/NGCP/Panel/Role/API/CallRecordings.pm
+++ b/lib/NGCP/Panel/Role/API/CallRecordings.pm
@@ -113,6 +113,7 @@ sub _item_rs {
     );
     if ($join_idx > 0) {
         $item_rs = $item_rs->search_rs(undef,{
+            distinct => 1,
             join => [ ('recording_metakeys') x $join_idx ],
         });
     }