diff options
Diffstat (limited to 'lib/public/DirectEditing')
-rw-r--r-- | lib/public/DirectEditing/ACreateEmpty.php | 59 | ||||
-rw-r--r-- | lib/public/DirectEditing/ACreateFromTemplate.php | 20 | ||||
-rw-r--r-- | lib/public/DirectEditing/ATemplate.php | 51 | ||||
-rw-r--r-- | lib/public/DirectEditing/IEditor.php | 81 | ||||
-rw-r--r-- | lib/public/DirectEditing/IManager.php | 82 | ||||
-rw-r--r-- | lib/public/DirectEditing/IToken.php | 65 | ||||
-rw-r--r-- | lib/public/DirectEditing/RegisterDirectEditorEvent.php | 40 |
7 files changed, 398 insertions, 0 deletions
diff --git a/lib/public/DirectEditing/ACreateEmpty.php b/lib/public/DirectEditing/ACreateEmpty.php new file mode 100644 index 00000000000..6ad499ec760 --- /dev/null +++ b/lib/public/DirectEditing/ACreateEmpty.php @@ -0,0 +1,59 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use OCP\Files\File; + +/** + * @since 18.0.0 + */ +abstract class ACreateEmpty { + /** + * Unique id for the creator to filter templates + * + * e.g. document/spreadsheet/presentation + * + * @since 18.0.0 + * @return string + */ + abstract public function getId(): string; + + /** + * Descriptive name for the create action + * + * e.g Create a new document + * + * @since 18.0.0 + * @return string + */ + abstract public function getName(): string; + + /** + * Default file extension for the new file + * + * @since 18.0.0 + * @return string + */ + abstract public function getExtension(): string; + + /** + * Mimetype of the resulting created file + * + * @since 18.0.0 + * @return string + */ + abstract public function getMimetype(): string; + + /** + * Add content when creating empty files + * + * @since 18.0.0 + * @param File $file + */ + public function create(File $file, ?string $creatorId = null, ?string $templateId = null): void { + } +} diff --git a/lib/public/DirectEditing/ACreateFromTemplate.php b/lib/public/DirectEditing/ACreateFromTemplate.php new file mode 100644 index 00000000000..e56e9c09cbb --- /dev/null +++ b/lib/public/DirectEditing/ACreateFromTemplate.php @@ -0,0 +1,20 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +/** + * @since 18.0.0 + */ +abstract class ACreateFromTemplate extends ACreateEmpty { + /** + * List of available templates for the create from template action + * + * @since 18.0.0 + * @return ATemplate[] + */ + abstract public function getTemplates(): array; +} diff --git a/lib/public/DirectEditing/ATemplate.php b/lib/public/DirectEditing/ATemplate.php new file mode 100644 index 00000000000..a70488d8e89 --- /dev/null +++ b/lib/public/DirectEditing/ATemplate.php @@ -0,0 +1,51 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use JsonSerializable; + +/** + * Class ATemplate + * + * @since 18.0.0 + */ +abstract class ATemplate implements JsonSerializable { + /** + * Return a unique id so the app can identify the template + * + * @since 18.0.0 + * @return string + */ + abstract public function getId(): string; + + /** + * Return a title that is displayed to the user + * + * @since 18.0.0 + * @return string + */ + abstract public function getTitle(): string; + + /** + * Return a link to the template preview image + * + * @since 18.0.0 + * @return string + */ + abstract public function getPreview(): string; + + /** + * @since 18.0.0 + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'title' => $this->getTitle(), + 'preview' => $this->getPreview(), + ]; + } +} diff --git a/lib/public/DirectEditing/IEditor.php b/lib/public/DirectEditing/IEditor.php new file mode 100644 index 00000000000..096af1d2a24 --- /dev/null +++ b/lib/public/DirectEditing/IEditor.php @@ -0,0 +1,81 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use OCP\AppFramework\Http\Response; + +/** + * @since 18.0.0 + */ +interface IEditor { + /** + * Return a unique identifier for the editor + * + * e.g. richdocuments + * + * @since 18.0.0 + * @return string + */ + public function getId(): string; + + /** + * Return a readable name for the editor + * + * e.g. Collabora Online + * + * @since 18.0.0 + * @return string + */ + public function getName(): string; + + /** + * A list of mimetypes that should open the editor by default + * + * @since 18.0.0 + * @return string[] + */ + public function getMimetypes(): array; + + /** + * A list of mimetypes that can be opened in the editor optionally + * + * @since 18.0.0 + * @return string[] + */ + public function getMimetypesOptional(): array; + + /** + * Return a list of file creation options to be presented to the user + * + * @since 18.0.0 + * @return ACreateFromTemplate[]|ACreateEmpty[] + */ + public function getCreators(): array; + + /** + * Return if the view is able to securely view a file without downloading it to the browser + * + * @since 18.0.0 + * @return bool + */ + public function isSecure(): bool; + + /** + * Return a template response for displaying the editor + * + * open can only be called once when the client requests the editor with a one-time-use token + * For handling editing and later requests, editors need to implement their own token handling and take care of invalidation + * + * This behavior is similar to the current direct editing implementation in collabora where we generate a one-time token and switch over to the regular wopi token for the actual editing/saving process + * + * @since 18.0.0 + * @return Response + */ + public function open(IToken $token): Response; +} diff --git a/lib/public/DirectEditing/IManager.php b/lib/public/DirectEditing/IManager.php new file mode 100644 index 00000000000..dcc3493bcf2 --- /dev/null +++ b/lib/public/DirectEditing/IManager.php @@ -0,0 +1,82 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use OCP\AppFramework\Http\Response; +use OCP\Files\NotPermittedException; +use RuntimeException; + +/** + * Interface IManager + * + * @since 18.0.0 + */ +interface IManager { + /** + * Register a new editor + * + * @since 18.0.0 + * @param IEditor $directEditor + */ + public function registerDirectEditor(IEditor $directEditor): void; + + /** + * Open the editing page for a provided token + * + * @since 18.0.0 + * @param string $token + * @return Response + */ + public function edit(string $token): Response; + + /** + * Create a new token based on the file path and editor details + * + * @since 18.0.0 + * @param string $path + * @param string $editorId + * @param string $creatorId + * @param null $templateId + * @return string + * @throws NotPermittedException + * @throws RuntimeException + */ + public function create(string $path, string $editorId, string $creatorId, $templateId = null): string; + + /** + * Get the token details for a given token + * + * @since 18.0.0 + * @param string $token + * @return IToken + */ + public function getToken(string $token): IToken; + + /** + * Cleanup expired tokens + * + * @since 18.0.0 + * @return int number of deleted tokens + */ + public function cleanup(): int; + + /** + * Check if direct editing is enabled + * + * @since 20.0.0 + * @return bool + */ + public function isEnabled(): bool; + + /** + * @since 24.0.0 + * @return IEditor[] + */ + public function getEditors(): array; +} diff --git a/lib/public/DirectEditing/IToken.php b/lib/public/DirectEditing/IToken.php new file mode 100644 index 00000000000..64abbf939f4 --- /dev/null +++ b/lib/public/DirectEditing/IToken.php @@ -0,0 +1,65 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use OCP\Files\File; +use OCP\Files\NotFoundException; + +/** + * @since 18.0.0 + */ +interface IToken { + /** + * Extend the token validity time + * + * @since 18.0.0 + */ + public function extend(): void; + + /** + * Invalidate the token + * + * @since 18.0.0 + */ + public function invalidate(): void; + + /** + * Check if the token has already been used + * + * @since 18.0.0 + * @return bool + */ + public function hasBeenAccessed(): bool; + + /** + * Change to the user scope of the token + * + * @since 18.0.0 + */ + public function useTokenScope(): void; + + /** + * Get the file that is related to the token + * + * @since 18.0.0 + * @return File + * @throws NotFoundException + */ + public function getFile(): File; + + /** + * @since 18.0.0 + * @return string + */ + public function getEditor(): string; + + /** + * @since 18.0.0 + * @return string + */ + public function getUser(): string; +} diff --git a/lib/public/DirectEditing/RegisterDirectEditorEvent.php b/lib/public/DirectEditing/RegisterDirectEditorEvent.php new file mode 100644 index 00000000000..cbf9b07185d --- /dev/null +++ b/lib/public/DirectEditing/RegisterDirectEditorEvent.php @@ -0,0 +1,40 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\DirectEditing; + +use OCP\EventDispatcher\Event; + +/** + * Event to allow to register the direct editor. + * + * @since 18.0.0 + */ +class RegisterDirectEditorEvent extends Event { + /** + * @var IManager + */ + private $manager; + + /** + * RegisterDirectEditorEvent constructor. + * + * @param IManager $manager + * @since 18.0.0 + */ + public function __construct(IManager $manager) { + parent::__construct(); + $this->manager = $manager; + } + + /** + * @since 18.0.0 + * @param IEditor $editor + */ + public function register(IEditor $editor): void { + $this->manager->registerDirectEditor($editor); + } +} |