fix(team-api): get all teams details in a single request

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
Maxence Lange 2025-09-08 13:02:34 -01:00 committed by provokateurin
parent 2552950299
commit 9ba3ce27cb
No known key found for this signature in database
4 changed files with 53 additions and 13 deletions

View file

@ -4297,6 +4297,11 @@
<code><![CDATA[$tag]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="lib/private/Teams/TeamManager.php">
<UndefinedDocblockClass>
<code><![CDATA[Circle]]></code>
</UndefinedDocblockClass>
</file>
<file src="lib/private/URLGenerator.php">
<InvalidReturnStatement>
<code><![CDATA[$path]]></code>

View file

@ -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,
]);
}
}

View file

@ -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);
}
}

View file

@ -40,4 +40,12 @@ interface ITeamManager {
* @since 29.0.0
*/
public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array;
/**
* @param list<Team> $teams
* @return array<string, list<TeamResource>>
*
* @since 33.0.0
*/
public function getSharedWithList(array $teams, string $userId): array;
}