diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 8b3c9ce6154..baca642cee9 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -4315,6 +4315,11 @@ + + + + + diff --git a/core/Controller/TeamsApiController.php b/core/Controller/TeamsApiController.php index ab29fdef77e..0dac1920ff8 100644 --- a/core/Controller/TeamsApiController.php +++ b/core/Controller/TeamsApiController.php @@ -66,15 +66,15 @@ class TeamsApiController extends OCSController { public function listTeams(string $providerId, string $resourceId): DataResponse { /** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */ $teams = $this->teamManager->getTeamsForResource($providerId, $resourceId, $this->userId); - $teams = array_values(array_map(function (Team $team) { + $sharesPerTeams = $this->teamManager->getSharedWithList(array_map(fn (Team $team): string => $team->getId(), $teams), $this->userId); + $listTeams = array_values(array_map(function (Team $team) use ($sharesPerTeams) { $response = $team->jsonSerialize(); - /** @psalm-suppress PossiblyNullArgument The route is limited to logged in users */ - $response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $this->teamManager->getSharedWith($team->getId(), $this->userId)); + $response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $sharesPerTeams[$team->getId()] ?? []); return $response; }, $teams)); return new DataResponse([ - 'teams' => $teams, + 'teams' => $listTeams, ]); } } diff --git a/lib/private/Teams/TeamManager.php b/lib/private/Teams/TeamManager.php index 13d6cc459a9..c5ede021d6d 100644 --- a/lib/private/Teams/TeamManager.php +++ b/lib/private/Teams/TeamManager.php @@ -84,24 +84,38 @@ class TeamManager implements ITeamManager { return array_values($resources); } + public function getSharedWithList(array $teams, string $userId): array { + if (!$this->hasTeamSupport()) { + return []; + } + + $resources = []; + foreach ($this->getProviders() as $provider) { + if (method_exists($provider, 'getSharedWithList')) { + $resources[] = $provider->getSharedWithList($teams, $userId); + } else { + foreach ($teams as $team) { + $resources[] = [$team->getId() => $provider->getSharedWith($team->getId())]; + } + } + } + + return array_merge_recursive(...$resources); + } + public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array { if (!$this->hasTeamSupport()) { return []; } $provider = $this->getProvider($providerId); - return array_values(array_filter(array_map(function ($teamId) use ($userId) { - $team = $this->getTeam($teamId, $userId); - if ($team === null) { - return null; - } - + return array_map(function (Circle $team) { return new Team( - $teamId, + $team->getSingleId(), $team->getDisplayName(), - $this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $teamId]), + $this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]), ); - }, $provider->getTeamsForResource($resourceId)))); + }, $this->getTeams($provider->getTeamsForResource($resourceId), $userId)); } private function getTeam(string $teamId, string $userId): ?Circle { @@ -117,4 +131,17 @@ class TeamManager implements ITeamManager { return null; } } + + /** + * @return Circle[] + */ + private function getTeams(array $teams, string $userId): array { + if (!$this->hasTeamSupport()) { + return []; + } + + $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); + $this->circlesManager->startSession($federatedUser); + return $this->circlesManager->getCirclesByIds($teams); + } } diff --git a/lib/public/Teams/ITeamManager.php b/lib/public/Teams/ITeamManager.php index 3f737b4229c..c0dc0d23be4 100644 --- a/lib/public/Teams/ITeamManager.php +++ b/lib/public/Teams/ITeamManager.php @@ -40,4 +40,12 @@ interface ITeamManager { * @since 29.0.0 */ public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array; + + /** + * @param list $teams + * @return array> + * + * @since 32.0.2 + */ + public function getSharedWithList(array $teams, string $userId): array; }