From aae372be52124a50a2af983b3177539e5763662e Mon Sep 17 00:00:00 2001 From: Andrey Borysenko Date: Tue, 10 Sep 2024 14:30:47 +0300 Subject: [PATCH] feat: add nextcloud url helper info endpoint to get instance base_url (#383) Added miscellaneous OCS method to get current Nextcloud instance base_url. image --------- Signed-off-by: Andrey Borysenko --- CHANGELOG.md | 3 ++- appinfo/routes.php | 1 + docs/tech_details/api/exapp.rst | 18 ++++++++++++++++++ lib/Controller/OCSExAppController.php | 9 +++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e09369f9..4dc7da49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [3.2.0 - 2024-09-09] +## [3.2.0 - 2024-09-10] ### Added - ExAppProxy: added bruteforce protection option for ExApp routes. #368 +- ExAppOCS: added miscellaneous method to get Nextcloud instance base URL. #383 ### Changed diff --git a/appinfo/routes.php b/appinfo/routes.php index f026ddde..018bbd4f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -64,6 +64,7 @@ ['name' => 'OCSApi#getEnabledState', 'url' => '/ex-app/state', 'verb' => 'GET'], // ExApps + ['name' => 'OCSExApp#getNextcloudUrl', 'url' => '/api/v1/info/nextcloud_url', 'verb' => 'GET'], ['name' => 'OCSExApp#getExAppsList', 'url' => '/api/v1/ex-app/{list}', 'verb' => 'GET'], ['name' => 'OCSExApp#getExApp', 'url' => '/api/v1/ex-app/info/{appId}', 'verb' => 'GET'], diff --git a/docs/tech_details/api/exapp.rst b/docs/tech_details/api/exapp.rst index c999f315..d3510d3c 100644 --- a/docs/tech_details/api/exapp.rst +++ b/docs/tech_details/api/exapp.rst @@ -59,6 +59,24 @@ Response data Returns HTTP 200 on success, HTTP 404 - on error. +Get Nextcloud URL +^^^^^^^^^^^^^^^^^ + +It might be necessary for ExApp to know (or update) the Nextcloud URL. + +OCS endpoint: ``GET /apps/app_api/api/v1/info/nextcloud_url`` + +Response data +************* + +Returns the base URL of the Nextcloud instance: + +.. code-block:: json + + { + "base_url": "http(s)://nextcloud.example.com" + } + Make Requests to ExApps ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/lib/Controller/OCSExAppController.php b/lib/Controller/OCSExAppController.php index 20c52084..97f34afc 100644 --- a/lib/Controller/OCSExAppController.php +++ b/lib/Controller/OCSExAppController.php @@ -14,6 +14,7 @@ use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCSController; use OCP\IRequest; +use OCP\IURLGenerator; class OCSExAppController extends OCSController { protected $request; @@ -22,6 +23,7 @@ public function __construct( IRequest $request, private readonly AppAPIService $service, private readonly ExAppService $exAppService, + private readonly IURLGenerator $urlGenerator, ) { parent::__construct(Application::APP_ID, $request); @@ -45,6 +47,13 @@ public function getExApp(string $appId): DataResponse { return new DataResponse($this->exAppService->formatExAppInfo($exApp), Http::STATUS_OK); } + #[NoCSRFRequired] + public function getNextcloudUrl(): DataResponse { + return new DataResponse([ + 'base_url' => $this->urlGenerator->getBaseUrl(), + ], Http::STATUS_OK); + } + /** * @throws OCSBadRequestException */