diff --git a/lib/FileSharingTeamResourceProvider.php b/lib/FileSharingTeamResourceProvider.php index 504f27466..bc9caff8c 100644 --- a/lib/FileSharingTeamResourceProvider.php +++ b/lib/FileSharingTeamResourceProvider.php @@ -42,7 +42,8 @@ public function getSharedWith(string $teamId): array { return []; } - $shares = $this->shareWrapperService->getSharesToCircle($teamId); + $shares = $this->shareWrapperService->filterAccessibleShares($this->shareWrapperService->getSharesToCircle($teamId)); + return $this->convertWrappedShareToResource($shares); } @@ -51,7 +52,8 @@ public function getSharedWith(string $teamId): array { */ public function getSharedWithList(array $teams, string $resourceId): array { $shares = $data = []; - foreach ($this->shareWrapperService->getSharesToCircles($teams, $resourceId) as $share) { + $accessibleShares = $this->shareWrapperService->filterAccessibleShares($this->shareWrapperService->getSharesToCircles($teams, $resourceId)); + foreach ($accessibleShares as $share) { $shares[$share->getSharedWith()][] = $share; } foreach ($teams as $teamId) { diff --git a/lib/Service/ShareWrapperService.php b/lib/Service/ShareWrapperService.php index bcfe2a73d..cc7dbc83d 100644 --- a/lib/Service/ShareWrapperService.php +++ b/lib/Service/ShareWrapperService.php @@ -237,6 +237,34 @@ private function refreshFileCaches(array $shares): array { return $refreshed; } + /** + * Keeps only shares with accessible files (not trashed, not deleted) + * + * @param ShareWrapper[] $shares + * + * @return ShareWrapper[] + */ + public function filterAccessibleShares(array $shares): array { + if ($shares === []) { + return []; + } + + $fileCaches = $this->shareWrapperRequest->getFileCaches( + array_map(fn (ShareWrapper $share): int => $share->getFileSource(), $shares) + ); + + $accessible = []; + foreach ($shares as $share) { + if (!array_key_exists($share->getFileSource(), $fileCaches) + || !$fileCaches[$share->getFileSource()]->isAccessible()) { + continue; + } + $accessible[] = $share; + } + + return $accessible; + } + /** * @return ShareWrapper[] * @throws RequestBuilderException