Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(core): Fix TeamsApiController typing
Signed-off-by: provokateurin <[email protected]>
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
provokateurin authored and ArtificialOwl committed Nov 10, 2025
commit c5b04713c43af8e06ec558b3363fee993ace39f0
14 changes: 6 additions & 8 deletions core/Controller/TeamsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
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 OCSController {
Expand All @@ -44,21 +46,18 @@ public function __construct(
#[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)]);
}

/**
* Get all teams of a resource
*
* @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
*/
Expand All @@ -67,11 +66,10 @@ public function resolveOne(string $teamId): DataResponse {
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) {
$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(), $this->teamManager->getSharedWith($team->getId(), $this->userId));
return $response;
}, $teams));

Expand Down
29 changes: 19 additions & 10 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,28 @@
* }
*
* @psalm-type CoreTeam = array{
* id: string,
* name: string,
* icon: string,
* teamId: string,
* displayName: string,
* link: ?string,
* }
*
* @psalm-type CoreTeamResource = array{
* id: int,
* label: string,
* url: string,
* iconSvg: ?string,
* iconURL: ?string,
* iconEmoji: ?string,
* }
* id: string,
* label: string,
* url: string,
* iconSvg: ?string,
* iconURL: ?string,
* iconEmoji: ?string,
* provider: array{
* id: string,
* name: string,
* icon: string,
* },
* }
*
* @psalm-type CoreTeamWithResources = CoreTeam&array{
* resources: list<CoreTeamResource>,
* }
*
* @psalm-type CoreTaskProcessingShape = array{
* name: string,
Expand Down
63 changes: 52 additions & 11 deletions core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,19 +898,20 @@
"Team": {
"type": "object",
"required": [
"id",
"name",
"icon"
"teamId",
"displayName",
"link"
],
"properties": {
"id": {
"teamId": {
"type": "string"
},
"name": {
"displayName": {
"type": "string"
},
"icon": {
"type": "string"
"link": {
"type": "string",
"nullable": true
}
}
},
Expand All @@ -922,12 +923,12 @@
"url",
"iconSvg",
"iconURL",
"iconEmoji"
"iconEmoji",
"provider"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
"type": "string"
},
"label": {
"type": "string"
Expand All @@ -946,9 +947,49 @@
"iconEmoji": {
"type": "string",
"nullable": true
},
"provider": {
"type": "object",
"required": [
"id",
"name",
"icon"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
}
}
}
},
"TeamWithResources": {
"allOf": [
{
"$ref": "#/components/schemas/Team"
},
{
"type": "object",
"required": [
"resources"
],
"properties": {
"resources": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TeamResource"
}
}
}
}
]
},
"TextProcessingTask": {
"type": "object",
"required": [
Expand Down Expand Up @@ -6306,7 +6347,7 @@
"teams": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Team"
"$ref": "#/components/schemas/TeamWithResources"
}
}
}
Expand Down
63 changes: 52 additions & 11 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,19 +898,20 @@
"Team": {
"type": "object",
"required": [
"id",
"name",
"icon"
"teamId",
"displayName",
"link"
],
"properties": {
"id": {
"teamId": {
"type": "string"
},
"name": {
"displayName": {
"type": "string"
},
"icon": {
"type": "string"
"link": {
"type": "string",
"nullable": true
}
}
},
Expand All @@ -922,12 +923,12 @@
"url",
"iconSvg",
"iconURL",
"iconEmoji"
"iconEmoji",
"provider"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
"type": "string"
},
"label": {
"type": "string"
Expand All @@ -946,9 +947,49 @@
"iconEmoji": {
"type": "string",
"nullable": true
},
"provider": {
"type": "object",
"required": [
"id",
"name",
"icon"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
}
}
}
},
"TeamWithResources": {
"allOf": [
{
"$ref": "#/components/schemas/Team"
},
{
"type": "object",
"required": [
"resources"
],
"properties": {
"resources": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TeamResource"
}
}
}
}
]
},
"TextProcessingTask": {
"type": "object",
"required": [
Expand Down Expand Up @@ -6306,7 +6347,7 @@
"teams": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Team"
"$ref": "#/components/schemas/TeamWithResources"
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/public/Teams/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public function getLink(): ?string {
}

/**
* @return array{
* teamId: string,
* displayName: string,
* link: ?string,
* }
*
* @since 29.0.0
*/
public function jsonSerialize(): array {
Expand Down
14 changes: 14 additions & 0 deletions lib/public/Teams/TeamResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public function getIconEmoji(): ?string {
}

/**
* @return array{
* id: string,
* label: string,
* url: string,
* iconSvg: ?string,
* iconURL: ?string,
* iconEmoji: ?string,
* provider: array{
* id: string,
* name: string,
* icon: string,
* },
* }
*
* @since 29.0.0
*/
public function jsonSerialize(): array {
Expand Down
Loading