From bc36cc808fb9ed9ff22c42246fe68f06cedb902e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Mon, 25 Nov 2019 13:56:22 +0100 Subject: [PATCH] Move editor list to capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files/appinfo/routes.php | 5 --- apps/files/lib/Capabilities.php | 43 ++++++++++++++++++- .../Controller/DirectEditingController.php | 42 ------------------ lib/private/DirectEditing/Manager.php | 9 +++- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 6f8a6878aac..f900b5ffbd8 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -99,11 +99,6 @@ $application->registerRoutes( ], ], 'ocs' => [ - [ - 'name' => 'DirectEditing#get', - 'url' => '/api/v1/directEditing', - 'verb' => 'GET' - ], [ 'name' => 'DirectEditing#templates', 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index 2b6bf57b90d..c37e32b6b59 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -25,7 +25,11 @@ namespace OCA\Files; +use OC\DirectEditing\Manager; use OCP\Capabilities\ICapability; +use OCP\DirectEditing\ACreateEmpty; +use OCP\DirectEditing\ACreateFromTemplate; +use OCP\DirectEditing\IEditor; use OCP\IConfig; /** @@ -42,8 +46,9 @@ class Capabilities implements ICapability { * * @param IConfig $config */ - public function __construct(IConfig $config) { + public function __construct(IConfig $config, Manager $manager) { $this->config = $config; + $this->directEditingManager = $manager; } /** @@ -56,7 +61,43 @@ class Capabilities implements ICapability { 'files' => [ 'bigfilechunking' => true, 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), + 'directEditing' => $this->getDirectEditingCapabilitites() ], ]; } + + private function getDirectEditingCapabilitites() { + $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, + 'name' => $creator->getName(), + 'extension' => $creator->getExtension(), + 'templates' => false + ]; + if ($creator instanceof ACreateFromTemplate) { + $capabilities['creators'][$id]['templates'] = true; + } + + } + } + return $capabilities; + } } diff --git a/apps/files/lib/Controller/DirectEditingController.php b/apps/files/lib/Controller/DirectEditingController.php index cf948d20f76..e8791316442 100644 --- a/apps/files/lib/Controller/DirectEditingController.php +++ b/apps/files/lib/Controller/DirectEditingController.php @@ -62,48 +62,6 @@ class DirectEditingController extends OCSController { $this->urlGenerator = $urlGenerator; } - /** - * @NoAdminRequired - * - * @return DataResponse - */ - public function get(): DataResponse { - $this->eventDispatcher->dispatch(RegisterDirectEditorEvent::class, 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, - 'name' => $creator->getName(), - 'extension' => $creator->getExtension(), - 'templates' => false - ]; - if ($creator instanceof ACreateFromTemplate) { - $capabilities['creators'][$id]['templates'] = true; - } - - } - } - return new DataResponse($capabilities); - } - /** * @NoAdminRequired */ diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index 353faedf7eb..fdf0a1f0f0f 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -32,6 +32,8 @@ use OCP\DirectEditing\ACreateFromTemplate; use OCP\DirectEditing\IEditor; use \OCP\DirectEditing\IManager; use OCP\DirectEditing\IToken; +use OCP\DirectEditing\RegisterDirectEditorEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; @@ -47,7 +49,7 @@ class Manager implements IManager { public const TABLE_TOKENS = 'direct_edit'; /** @var IEditor[] */ - private $editors; + private $editors = []; /** @var IDBConnection */ private $connection; @@ -62,12 +64,15 @@ class Manager implements IManager { ISecureRandom $random, IDBConnection $connection, IUserSession $userSession, - IRootFolder $rootFolder + IRootFolder $rootFolder, + IEventDispatcher $eventDispatcher ) { $this->random = $random; $this->connection = $connection; $this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null; $this->rootFolder = $rootFolder; + $eventDispatcher->dispatch(RegisterDirectEditorEvent::class, new RegisterDirectEditorEvent($this)); + } public function registerDirectEditor(IEditor $directEditor): void { -- 2.39.5