From 03e4ba82f7fb8923c7d905ac39c4babcc2e2aa3c Mon Sep 17 00:00:00 2001 From: Tom Wezepoel Date: Tue, 12 Nov 2024 09:42:37 +0100 Subject: [PATCH] Exclude groups for sharing --- .../lib/Controller/ShareesAPIController.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 3a04dda72a199..21d5df14d51fc 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -197,6 +197,27 @@ public function search(string $search = '', ?string $itemType = null, int $page $result['exact'] = array_merge($this->result['exact'], $result['exact']); } $this->result = array_merge($this->result, $result); + + // Get a list of groups to exclude from search results + $blacklisted_groups = $this->config->getSystemValue('blacklisted_groups', true); + + // Check and filter normal 'groups' array at the top level and the nested 'exact' level + if (isset($this->result['groups'])) { + $this->result['groups'] = array_filter($this->result['groups'], function($group) use ($blacklisted_groups) { + return !in_array($group['label'], $blacklisted_groups); + }); + // Reindex array to maintain sequential numeric keys + $this->result['groups'] = array_values($this->result['groups']); + } + + if (isset($this->result['exact']['groups'])) { + $this->result['exact']['groups'] = array_filter($this->result['exact']['groups'], function($group) use ($blacklisted_groups) { + return !in_array($group['label'], $blacklisted_groups); + }); + // Reindex array to maintain sequential numeric keys + $this->result['exact']['groups'] = array_values($this->result['exact']['groups']); + } + $response = new DataResponse($this->result); if ($hasMoreResults) {