|
|
|
|
@ -16,10 +16,12 @@ use OCP\AppFramework\Http\DataResponse;
|
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
use OCP\Teams\ITeamManager;
|
|
|
|
|
use OCP\Teams\Team;
|
|
|
|
|
use OCP\Teams\TeamResource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @psalm-import-type CoreTeamResource from ResponseDefinitions
|
|
|
|
|
* @psalm-import-type CoreTeam from ResponseDefinitions
|
|
|
|
|
* @psalm-import-type CoreTeamWithResources from ResponseDefinitions
|
|
|
|
|
* @property $userId string
|
|
|
|
|
*/
|
|
|
|
|
class TeamsApiController extends \OCP\AppFramework\OCSController {
|
|
|
|
|
@ -43,13 +45,10 @@ class TeamsApiController extends \OCP\AppFramework\OCSController {
|
|
|
|
|
#[NoAdminRequired]
|
|
|
|
|
#[ApiRoute(verb: 'GET', url: '/{teamId}/resources', root: '/teams')]
|
|
|
|
|
public function resolveOne(string $teamId): DataResponse {
|
|
|
|
|
/**
|
|
|
|
|
* @var list<CoreTeamResource> $resolvedResources
|
|
|
|
|
* @psalm-suppress PossiblyNullArgument The route is limited to logged-in users
|
|
|
|
|
*/
|
|
|
|
|
/** @psalm-suppress PossiblyNullArgument The route is limited to logged-in users */
|
|
|
|
|
$resolvedResources = $this->teamManager->getSharedWith($teamId, $this->userId);
|
|
|
|
|
|
|
|
|
|
return new DataResponse(['resources' => $resolvedResources]);
|
|
|
|
|
return new DataResponse(['resources' => array_map(static fn (TeamResource $resource) => $resource->jsonSerialize(), $resolvedResources)]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -57,7 +56,7 @@ class TeamsApiController extends \OCP\AppFramework\OCSController {
|
|
|
|
|
*
|
|
|
|
|
* @param string $providerId Identifier of the provider (e.g. deck, talk, collectives)
|
|
|
|
|
* @param string $resourceId Unique id of the resource to list teams for (e.g. deck board id)
|
|
|
|
|
* @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeam>}, array{}>
|
|
|
|
|
* @return DataResponse<Http::STATUS_OK, array{teams: list<CoreTeamWithResources>}, array{}>
|
|
|
|
|
*
|
|
|
|
|
* 200: Teams returned
|
|
|
|
|
*/
|
|
|
|
|
@ -66,16 +65,16 @@ class TeamsApiController extends \OCP\AppFramework\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);
|
|
|
|
|
/** @var list<CoreTeam> $teams */
|
|
|
|
|
$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'] = $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,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|