Merge pull request #59903 from nextcloud/fix/noid/teams-api-resource-filter

fix(teams-api): adjust resource filtering
This commit is contained in:
Cristian Scheid 2026-04-27 08:22:04 -03:00 committed by GitHub
commit f7777c30b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -66,7 +66,8 @@ 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);
$sharesPerTeams = $this->teamManager->getSharedWithList(array_map(static fn (Team $team): string => $team->getId(), $teams), $this->userId);
$teamIds = array_map(static fn (Team $team): string => $team->getId(), $teams);
$sharesPerTeams = $this->teamManager->getSharedWithList($teamIds, $this->userId, $resourceId);
$listTeams = array_values(array_map(static function (Team $team) use ($sharesPerTeams) {
$response = $team->jsonSerialize();
$response['resources'] = array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $sharesPerTeams[$team->getId()] ?? []);

View file

@ -84,7 +84,7 @@ class TeamManager implements ITeamManager {
return array_values($resources);
}
public function getSharedWithList(array $teams, string $userId): array {
public function getSharedWithList(array $teams, string $userId, string $resourceId): array {
if (!$this->hasTeamSupport()) {
return [];
}
@ -92,7 +92,7 @@ class TeamManager implements ITeamManager {
$resources = [];
foreach ($this->getProviders() as $provider) {
if (method_exists($provider, 'getSharedWithList')) {
$resources[] = $provider->getSharedWithList($teams, $userId);
$resources[] = $provider->getSharedWithList($teams, $resourceId);
} else {
foreach ($teams as $team) {
$resources[] = [$team => $provider->getSharedWith($team)];

View file

@ -42,12 +42,13 @@ interface ITeamManager {
public function getTeamsForResource(string $providerId, string $resourceId, string $userId): array;
/**
* @param string[] $teams
* @return array<string, list<TeamResource>>
* Returns all team resources for the given teams, user and resource
*
* @return array<string, list<TeamResource>>
* @since 33.0.0
* @since 34.0.0 Added $resourceId param
*/
public function getSharedWithList(array $teams, string $userId): array;
public function getSharedWithList(array $teams, string $userId, string $resourceId): array;
/**
* Returns all teams that a given user is a member of