Skip to content

Commit

Permalink
Merge pull request #43855 from nextcloud/feat/team-provider
Browse files Browse the repository at this point in the history
Implement team provider api
  • Loading branch information
juliushaertl authored Mar 5, 2024
2 parents d65e46f + c7813bf commit ad8cb2c
Show file tree
Hide file tree
Showing 17 changed files with 929 additions and 6 deletions.
97 changes: 97 additions & 0 deletions core/Controller/TeamsApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OC\Core\Controller;

use OCA\Core\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\Teams\ITeamManager;
use OCP\Teams\Team;

/**
* @psalm-import-type CoreTeamResource from ResponseDefinitions
* @psalm-import-type CoreTeam from ResponseDefinitions
* @property $userId string
*/
class TeamsApiController extends \OCP\AppFramework\OCSController {
public function __construct(
string $appName,
IRequest $request,
private ITeamManager $teamManager,
private ?string $userId,
) {
parent::__construct($appName, $request);
}

/**
* Get all resources of a team
*
* @param string $teamId Unique id of the team
* @return DataResponse<Http::STATUS_OK, array{resources: CoreTeamResource[]}, array{}>
*
* 200: Resources returned
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/{teamId}/resources', root: '/teams')]
public function resolveOne(string $teamId): DataResponse {
/**
* @var CoreTeamResource[] $resolvedResources
* @psalm-suppress PossiblyNullArgument The route is limited to logged-in users
*/
$resolvedResources = $this->teamManager->getSharedWith($teamId, $this->userId);

return new DataResponse(['resources' => $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: CoreTeam[]}, array{}>
*
* 200: Teams returned
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/resources/{providerId}/{resourceId}', root: '/teams')]
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 CoreTeam[] $teams */
$teams = 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);
return $response;
}, $teams);

return new DataResponse([
'teams' => $teams,
]);
}
}
15 changes: 15 additions & 0 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@
* numberOfImages: int,
* completionExpectedAt: ?int,
* }
*
* @psalm-type CoreTeam = array{
* id: string,
* name: string,
* icon: string,
* }
*
* @psalm-type CoreTeamResource = array{
* id: int,
* label: string,
* url: string,
* iconSvg: ?string,
* iconURL: ?string,
* iconEmoji: ?string,
* }
*/
class ResponseDefinitions {
}
225 changes: 225 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,60 @@
}
}
},
"Team": {
"type": "object",
"required": [
"id",
"name",
"icon"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
}
},
"TeamResource": {
"type": "object",
"required": [
"id",
"label",
"url",
"iconSvg",
"iconURL",
"iconEmoji"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"label": {
"type": "string"
},
"url": {
"type": "string"
},
"iconSvg": {
"type": "string",
"nullable": true
},
"iconURL": {
"type": "string",
"nullable": true
},
"iconEmoji": {
"type": "string",
"nullable": true
}
}
},
"TextProcessingTask": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3009,6 +3063,177 @@
}
}
},
"/ocs/v2.php/teams/{teamId}/resources": {
"get": {
"operationId": "teams_api-resolve-one",
"summary": "Get all resources of a team",
"tags": [
"teams_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "teamId",
"in": "path",
"description": "Unique id of the team",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Resources returned",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"resources"
],
"properties": {
"resources": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TeamResource"
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/teams/resources/{providerId}/{resourceId}": {
"get": {
"operationId": "teams_api-list-teams",
"summary": "Get all teams of a resource",
"tags": [
"teams_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "providerId",
"in": "path",
"description": "Identifier of the provider (e.g. deck, talk, collectives)",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "resourceId",
"in": "path",
"description": "Unique id of the resource to list teams for (e.g. deck board id)",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Teams returned",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"teams"
],
"properties": {
"teams": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Team"
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/textprocessing/tasktypes": {
"get": {
"operationId": "text_processing_api-task-types",
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copyright (c) Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -17,3 +18,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

6 changes: 6 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@
'OCP\\Talk\\IConversation' => $baseDir . '/lib/public/Talk/IConversation.php',
'OCP\\Talk\\IConversationOptions' => $baseDir . '/lib/public/Talk/IConversationOptions.php',
'OCP\\Talk\\ITalkBackend' => $baseDir . '/lib/public/Talk/ITalkBackend.php',
'OCP\\Teams\\ITeamManager' => $baseDir . '/lib/public/Teams/ITeamManager.php',
'OCP\\Teams\\ITeamResourceProvider' => $baseDir . '/lib/public/Teams/ITeamResourceProvider.php',
'OCP\\Teams\\Team' => $baseDir . '/lib/public/Teams/Team.php',
'OCP\\Teams\\TeamResource' => $baseDir . '/lib/public/Teams/TeamResource.php',
'OCP\\Template' => $baseDir . '/lib/public/Template.php',
'OCP\\TextProcessing\\Events\\AbstractTextProcessingEvent' => $baseDir . '/lib/public/TextProcessing/Events/AbstractTextProcessingEvent.php',
'OCP\\TextProcessing\\Events\\TaskFailedEvent' => $baseDir . '/lib/public/TextProcessing/Events/TaskFailedEvent.php',
Expand Down Expand Up @@ -1158,6 +1162,7 @@
'OC\\Core\\Controller\\ReferenceController' => $baseDir . '/core/Controller/ReferenceController.php',
'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php',
'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php',
'OC\\Core\\Controller\\TeamsApiController' => $baseDir . '/core/Controller/TeamsApiController.php',
'OC\\Core\\Controller\\TextProcessingApiController' => $baseDir . '/core/Controller/TextProcessingApiController.php',
'OC\\Core\\Controller\\TextToImageApiController' => $baseDir . '/core/Controller/TextToImageApiController.php',
'OC\\Core\\Controller\\TranslationApiController' => $baseDir . '/core/Controller/TranslationApiController.php',
Expand Down Expand Up @@ -1794,6 +1799,7 @@
'OC\\Tags' => $baseDir . '/lib/private/Tags.php',
'OC\\Talk\\Broker' => $baseDir . '/lib/private/Talk/Broker.php',
'OC\\Talk\\ConversationOptions' => $baseDir . '/lib/private/Talk/ConversationOptions.php',
'OC\\Teams\\TeamManager' => $baseDir . '/lib/private/Teams/TeamManager.php',
'OC\\TempManager' => $baseDir . '/lib/private/TempManager.php',
'OC\\TemplateLayout' => $baseDir . '/lib/private/TemplateLayout.php',
'OC\\Template\\Base' => $baseDir . '/lib/private/Template/Base.php',
Expand Down
Loading

0 comments on commit ad8cb2c

Please sign in to comment.