diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-11-27 14:36:07 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-11-27 19:56:45 +0100 |
commit | bde624b07423de4a6b9e3aaae6371cd4f886c2de (patch) | |
tree | ef1855174a172091b43c9041379073776ed69aa2 /apps | |
parent | fb1b88ac63bbc171104559ce3a5ea0d84791249e (diff) | |
download | nextcloud-server-bde624b07423de4a6b9e3aaae6371cd4f886c2de.tar.gz nextcloud-server-bde624b07423de4a6b9e3aaae6371cd4f886c2de.zip |
Only expose link to info endpoint in capabilties
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/appinfo/routes.php | 5 | ||||
-rw-r--r-- | apps/files/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/files/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/files/lib/Capabilities.php | 54 | ||||
-rw-r--r-- | apps/files/lib/Controller/DirectEditingController.php | 16 | ||||
-rw-r--r-- | apps/files/lib/Service/DirectEditingService.php | 85 |
6 files changed, 120 insertions, 42 deletions
diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index f900b5ffbd8..9d889fe0e69 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -100,6 +100,11 @@ $application->registerRoutes( ], 'ocs' => [ [ + 'name' => 'DirectEditing#info', + 'url' => '/api/v1/directEditing', + 'verb' => 'GET' + ], + [ 'name' => 'DirectEditing#templates', 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', 'verb' => 'GET' diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index 462e51ffe09..b350bfae07e 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -40,6 +40,7 @@ return array( 'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', + 'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php', ); diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index b41faa6f8c3..34a64f32531 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -55,6 +55,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', + 'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php', ); diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index 1318a56f717..20ef0c4d229 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -26,6 +26,7 @@ namespace OCA\Files; use OC\DirectEditing\Manager; +use OCA\Files\Service\DirectEditingService; use OCP\Capabilities\ICapability; use OCP\DirectEditing\ACreateEmpty; use OCP\DirectEditing\ACreateFromTemplate; @@ -33,6 +34,7 @@ use OCP\DirectEditing\IEditor; use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; +use OCP\IURLGenerator; /** * Class Capabilities @@ -44,21 +46,21 @@ class Capabilities implements ICapability { /** @var IConfig */ protected $config; - /** @var Manager */ - protected $directEditingManager; + /** @var DirectEditingService */ + protected $directEditingService; - /** @var IEventDispatcher */ - protected $eventDispatcher; + /** @var IURLGenerator */ + private $urlGenerator; /** * Capabilities constructor. * * @param IConfig $config */ - public function __construct(IConfig $config, Manager $manager, IEventDispatcher $eventDispatcher) { + public function __construct(IConfig $config, DirectEditingService $directEditingService, IURLGenerator $urlGenerator) { $this->config = $config; - $this->directEditingManager = $manager; - $this->eventDispatcher = $eventDispatcher; + $this->directEditingService = $directEditingService; + $this->urlGenerator = $urlGenerator; } /** @@ -71,43 +73,13 @@ class Capabilities implements ICapability { 'files' => [ 'bigfilechunking' => true, 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), - 'directEditing' => $this->getDirectEditingCapabilitites() + 'directEditing' => [ + 'url' => $this->urlGenerator->linkToOCSRouteAbsolute('files.DirectEditing.info'), + 'etag' => $this->directEditingService->getDirectEditingETag() + ] ], ]; } - private function getDirectEditingCapabilitites(): array { - $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); - $capabilities = [ - 'editors' => [], - 'creators' => [] - ]; - - /** - * @var string $id - * @var IEditor $editor - */ - foreach ($this->directEditingManager->getEditors() as $id => $editor) { - $capabilities['editors'][$id] = [ - 'name' => $editor->getName(), - 'mimetypes' => $editor->getMimetypes(), - 'optionalMimetypes' => $editor->getMimetypesOptional(), - 'secure' => $editor->isSecure(), - ]; - /** @var ACreateEmpty|ACreateFromTemplate $creator */ - foreach ($editor->getCreators() as $creator) { - $id = $creator->getId(); - $capabilities['creators'][$id] = [ - 'id' => $id, - 'editor' => $editor->getId(), - 'name' => $creator->getName(), - 'extension' => $creator->getExtension(), - 'templates' => $creator instanceof ACreateFromTemplate, - 'mimetype' => $creator->getMimetype() - ]; - } - } - return $capabilities; - } } diff --git a/apps/files/lib/Controller/DirectEditingController.php b/apps/files/lib/Controller/DirectEditingController.php index 11d09e2f074..0a086c3da60 100644 --- a/apps/files/lib/Controller/DirectEditingController.php +++ b/apps/files/lib/Controller/DirectEditingController.php @@ -25,6 +25,7 @@ namespace OCA\Files\Controller; use Exception; +use OCA\Files\Service\DirectEditingService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; @@ -52,12 +53,16 @@ class DirectEditingController extends OCSController { /** @var ILogger */ private $logger; + /** @var DirectEditingService */ + private $directEditingService; + public function __construct($appName, IRequest $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge, - IEventDispatcher $eventDispatcher, IURLGenerator $urlGenerator, IManager $manager, ILogger $logger) { + IEventDispatcher $eventDispatcher, IURLGenerator $urlGenerator, IManager $manager, DirectEditingService $directEditingService, ILogger $logger) { parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge); $this->eventDispatcher = $eventDispatcher; $this->directEditingManager = $manager; + $this->directEditingService = $directEditingService; $this->logger = $logger; $this->urlGenerator = $urlGenerator; } @@ -65,6 +70,15 @@ class DirectEditingController extends OCSController { /** * @NoAdminRequired */ + public function info(): DataResponse { + $response = new DataResponse($this->directEditingService->getDirectEditingCapabilitites()); + $response->setETag($this->directEditingService->getDirectEditingETag()); + return $response; + } + + /** + * @NoAdminRequired + */ public function create(string $path, string $editorId, string $creatorId, string $templateId = null): DataResponse { $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); diff --git a/apps/files/lib/Service/DirectEditingService.php b/apps/files/lib/Service/DirectEditingService.php new file mode 100644 index 00000000000..7e906238d87 --- /dev/null +++ b/apps/files/lib/Service/DirectEditingService.php @@ -0,0 +1,85 @@ +<?php +/** + * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 OCA\Files\Service; + + +use OCP\DirectEditing\ACreateEmpty; +use OCP\DirectEditing\ACreateFromTemplate; +use OCP\DirectEditing\IEditor; +use OCP\DirectEditing\IManager; +use OCP\DirectEditing\RegisterDirectEditorEvent; +use OCP\EventDispatcher\IEventDispatcher; + +class DirectEditingService { + + /** @var IManager */ + private $directEditingManager; + /** @var IEventDispatcher */ + private $eventDispatcher; + + public function __construct(IEventDispatcher $eventDispatcher, IManager $directEditingManager) { + $this->directEditingManager = $directEditingManager; + $this->eventDispatcher = $eventDispatcher; + } + + public function getDirectEditingETag(): string { + return \md5(\json_encode($this->getDirectEditingCapabilitites())); + } + + public function getDirectEditingCapabilitites(): array { + $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); + + $capabilities = [ + 'editors' => [], + 'creators' => [] + ]; + + /** + * @var string $id + * @var IEditor $editor + */ + foreach ($this->directEditingManager->getEditors() as $id => $editor) { + $capabilities['editors'][$id] = [ + 'name' => $editor->getName(), + 'mimetypes' => $editor->getMimetypes(), + 'optionalMimetypes' => $editor->getMimetypesOptional(), + 'secure' => $editor->isSecure(), + ]; + /** @var ACreateEmpty|ACreateFromTemplate $creator */ + foreach ($editor->getCreators() as $creator) { + $id = $creator->getId(); + $capabilities['creators'][$id] = [ + 'id' => $id, + 'editor' => $editor->getId(), + 'name' => $creator->getName(), + 'extension' => $creator->getExtension(), + 'templates' => $creator instanceof ACreateFromTemplate, + 'mimetype' => $creator->getMimetype() + ]; + } + } + return $capabilities; + } + +} |