diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2023-09-19 21:49:19 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2023-09-20 08:23:45 -0100 |
commit | b5dcd048ae85cfe8d7fb22663f1955efbdca7921 (patch) | |
tree | 0aba878eec4ee9222e4de538f229be908535cd3c | |
parent | c6c06d517cfe80f1a75c7eff2b66fb9cefea86d9 (diff) | |
download | nextcloud-server-b5dcd048ae85cfe8d7fb22663f1955efbdca7921.tar.gz nextcloud-server-b5dcd048ae85cfe8d7fb22663f1955efbdca7921.zip |
small fixes
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php | 5 | ||||
-rw-r--r-- | build/psalm-baseline.xml | 5 | ||||
-rw-r--r-- | core/Controller/OCMController.php | 16 | ||||
-rw-r--r-- | core/openapi.json | 110 | ||||
-rw-r--r-- | lib/private/OCM/Model/OCMProvider.php | 2 |
5 files changed, 126 insertions, 12 deletions
diff --git a/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php b/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php index 1d58629b98f..75606960e4b 100644 --- a/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php +++ b/apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php @@ -33,6 +33,7 @@ use OCP\IDBConnection; use OCP\OCM\Exceptions\OCMProviderException; use OCP\OCM\IOCMDiscoveryService; use OCP\OCS\IDiscoveryService; +use Psr\Log\LoggerInterface; class FederatedSharesDiscoverJob extends TimedJob { @@ -40,7 +41,8 @@ class FederatedSharesDiscoverJob extends TimedJob { ITimeFactory $time, private IDBConnection $connection, private IDiscoveryService $discoveryService, - private IOCMDiscoveryService $ocmDiscoveryService + private IOCMDiscoveryService $ocmDiscoveryService, + private LoggerInterface $logger, ) { parent::__construct($time); $this->setInterval(86400); @@ -58,6 +60,7 @@ class FederatedSharesDiscoverJob extends TimedJob { try { $this->ocmDiscoveryService->discover($row['remote'], true); } catch (OCMProviderException $e) { + $this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]); } } $result->closeCursor(); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index b311f0fa830..b54f19b8ee3 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -43,11 +43,6 @@ <code>IEventListener</code> </MissingTemplateParam> </file> - <file src="apps/cloud_federation_api/lib/Capabilities.php"> - <LessSpecificImplementedReturnType> - <code>array</code> - </LessSpecificImplementedReturnType> - </file> <file src="apps/comments/lib/Listener/CommentsEntityEventListener.php"> <MissingTemplateParam> <code>IEventListener</code> diff --git a/core/Controller/OCMController.php b/core/Controller/OCMController.php index 421803439b0..8d08da1f8e4 100644 --- a/core/Controller/OCMController.php +++ b/core/Controller/OCMController.php @@ -29,9 +29,8 @@ namespace OC\Core\Controller; use Exception; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; -use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; use OCP\AppFramework\Http\DataResponse; -use OCP\AppFramework\Http\Response; +use OCP\Capabilities\ICapability; use OCP\IConfig; use OCP\IRequest; use OCP\Server; @@ -58,11 +57,14 @@ class OCMController extends Controller { * * @PublicPage * @NoCSRFRequired + * @psalm-suppress MoreSpecificReturnType + * @psalm-suppress LessSpecificReturnStatement + * @return DataResponse<Http::STATUS_OK, array{enabled: bool, apiVersion: string, endPoint: string, resourceTypes: array{array{name: string, shareTypes: string[], protocols: array{webdav: string}}}}, array{X-NEXTCLOUD-OCM-PROVIDERS: true, Content-Type: 'application/json'}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> * - * @return Response + * 200: OCM Provider details returned + * 500: OCM not supported */ - #[IgnoreOpenAPI] - public function discovery(): Response { + public function discovery(): DataResponse { try { $cap = Server::get( $this->config->getAppValue( @@ -72,6 +74,10 @@ class OCMController extends Controller { ) ); + if (!($cap instanceof ICapability)) { + throw new Exception('loaded class does not implements OCP\Capabilities\ICapability'); + } + return new DataResponse( $cap->getCapabilities()['ocm'] ?? ['enabled' => false], Http::STATUS_OK, diff --git a/core/openapi.json b/core/openapi.json index 3a67a076988..95fc7c2ff9f 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -1289,6 +1289,116 @@ } } }, + "/index.php/ocm-provider": { + "get": { + "operationId": "ocm-discovery", + "summary": "generate a OCMProvider with local data and send it as DataResponse. This replaces the old PHP file ocm-provider/index.php", + "tags": [ + "ocm" + ], + "security": [ + {}, + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "responses": { + "200": { + "description": "OCM Provider details returned", + "headers": { + "X-NEXTCLOUD-OCM-PROVIDERS": { + "schema": { + "type": "boolean" + } + } + }, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "enabled", + "apiVersion", + "endPoint", + "resourceTypes" + ], + "properties": { + "enabled": { + "type": "boolean" + }, + "apiVersion": { + "type": "string" + }, + "endPoint": { + "type": "string" + }, + "resourceTypes": { + "type": "object", + "required": [ + null + ], + "properties": { + "": { + "type": "object", + "required": [ + "name", + "shareTypes", + "protocols" + ], + "properties": { + "name": { + "type": "string" + }, + "shareTypes": { + "type": "array", + "items": { + "type": "string" + } + }, + "protocols": { + "type": "object", + "required": [ + "webdav" + ], + "properties": { + "webdav": { + "type": "string" + } + } + } + } + } + } + } + } + } + } + } + }, + "500": { + "description": "OCM not supported", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/cloud/capabilities": { "get": { "operationId": "ocs-get-capabilities", diff --git a/lib/private/OCM/Model/OCMProvider.php b/lib/private/OCM/Model/OCMProvider.php index 40ef43085b3..44f4fbebc10 100644 --- a/lib/private/OCM/Model/OCMProvider.php +++ b/lib/private/OCM/Model/OCMProvider.php @@ -196,7 +196,7 @@ class OCMProvider implements IOCMProvider, JsonSerializable { * } */ public function jsonSerialize(): array { - $resourceTypes = []; // this is needed for psalm + $resourceTypes = []; foreach ($this->getResourceTypes() as $res) { $resourceTypes[] = $res->jsonSerialize(); } |