Only expose link to info endpoint in capabilties
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
fb1b88ac63
commit
bde624b074
6 changed files with 120 additions and 42 deletions
|
@ -99,6 +99,11 @@ $application->registerRoutes(
|
|||
],
|
||||
],
|
||||
'ocs' => [
|
||||
[
|
||||
'name' => 'DirectEditing#info',
|
||||
'url' => '/api/v1/directEditing',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
[
|
||||
'name' => 'DirectEditing#templates',
|
||||
'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}',
|
||||
|
|
|
@ -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',
|
||||
);
|
||||
|
|
|
@ -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',
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,16 +53,29 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function info(): DataResponse {
|
||||
$response = new DataResponse($this->directEditingService->getDirectEditingCapabilitites());
|
||||
$response->setETag($this->directEditingService->getDirectEditingETag());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
|
|
85
apps/files/lib/Service/DirectEditingService.php
Normal file
85
apps/files/lib/Service/DirectEditingService.php
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue