Skip to content
Snippets Groups Projects
Unverified Commit e29a76bc authored by Julius Härtl's avatar Julius Härtl
Browse files

Use file path for direct editing


Signed-off-by: default avatarJulius Härtl <jus@bitgrid.net>
parent 6f540fc0
No related branches found
No related tags found
No related merge requests found
...@@ -96,11 +96,11 @@ class DirectEditingController extends OCSController { ...@@ -96,11 +96,11 @@ class DirectEditingController extends OCSController {
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function open(int $fileId, string $editorId = null): DataResponse { public function open(string $path, string $editorId = null): DataResponse {
$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager)); $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
try { try {
$token = $this->directEditingManager->open($fileId, $editorId); $token = $this->directEditingManager->open($path, $editorId);
return new DataResponse([ return new DataResponse([
'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token]) 'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token])
]); ]);
......
<?php
declare(strict_types=1);
/**
* @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 OC\Core\Migrations;
use Closure;
use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
class Version18000Date20191204114856 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('direct_edit');
$table->addColumn('file_path', 'string', [
'notnull' => false,
'length' => 4000,
]);
return $schema;
}
}
...@@ -804,6 +804,7 @@ return array( ...@@ -804,6 +804,7 @@ return array(
'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php',
'OC\\Core\\Migrations\\Version18000Date20190920085628' => $baseDir . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => $baseDir . '/core/Migrations/Version18000Date20190920085628.php',
'OC\\Core\\Migrations\\Version18000Date20191014105105' => $baseDir . '/core/Migrations/Version18000Date20191014105105.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => $baseDir . '/core/Migrations/Version18000Date20191014105105.php',
'OC\\Core\\Migrations\\Version18000Date20191204114856' => $baseDir . '/core/Migrations/Version18000Date20191204114856.php',
'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
......
...@@ -833,6 +833,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c ...@@ -833,6 +833,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php',
'OC\\Core\\Migrations\\Version18000Date20190920085628' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20190920085628.php',
'OC\\Core\\Migrations\\Version18000Date20191014105105' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191014105105.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191014105105.php',
'OC\\Core\\Migrations\\Version18000Date20191204114856' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191204114856.php',
'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
......
...@@ -36,6 +36,7 @@ use OCP\DirectEditing\RegisterDirectEditorEvent; ...@@ -36,6 +36,7 @@ use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IUserSession; use OCP\IUserSession;
...@@ -103,25 +104,21 @@ class Manager implements IManager { ...@@ -103,25 +104,21 @@ class Manager implements IManager {
foreach ($creators as $creator) { foreach ($creators as $creator) {
if ($creator->getId() === $creatorId) { if ($creator->getId() === $creatorId) {
$creator->create($file, $creatorId, $templateId); $creator->create($file, $creatorId, $templateId);
return $this->createToken($editorId, $file); return $this->createToken($editorId, $file, $path);
} }
} }
throw new \RuntimeException('No creator found'); throw new \RuntimeException('No creator found');
} }
public function open(int $fileId, string $editorId = null): string { public function open(string $filePath, string $editorId = null): string {
$file = $this->rootFolder->getUserFolder($this->userId)->getById($fileId);
if (count($file) === 0 || !($file[0] instanceof File) || $file === null) {
throw new NotFoundException();
}
/** @var File $file */ /** @var File $file */
$file = $file[0]; $file = $this->rootFolder->getUserFolder($this->userId)->get($filePath);
if ($editorId === null) { if ($editorId === null) {
$editorId = $this->findEditorForFile($file); $editorId = $this->findEditorForFile($file);
} }
return $this->createToken($editorId, $file); return $this->createToken($editorId, $file, $filePath);
} }
private function findEditorForFile(File $file) { private function findEditorForFile(File $file) {
...@@ -212,7 +209,7 @@ class Manager implements IManager { ...@@ -212,7 +209,7 @@ class Manager implements IManager {
\OC_User::setUserId($userId); \OC_User::setUserId($userId);
} }
public function createToken($editorId, File $file, IShare $share = null): string { public function createToken($editorId, File $file, string $filePath, IShare $share = null): string {
$token = $this->random->generate(64, ISecureRandom::CHAR_HUMAN_READABLE); $token = $this->random->generate(64, ISecureRandom::CHAR_HUMAN_READABLE);
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->insert(self::TABLE_TOKENS) $query->insert(self::TABLE_TOKENS)
...@@ -220,6 +217,7 @@ class Manager implements IManager { ...@@ -220,6 +217,7 @@ class Manager implements IManager {
'token' => $query->createNamedParameter($token), 'token' => $query->createNamedParameter($token),
'editor_id' => $query->createNamedParameter($editorId), 'editor_id' => $query->createNamedParameter($editorId),
'file_id' => $query->createNamedParameter($file->getId()), 'file_id' => $query->createNamedParameter($file->getId()),
'file_path' => $query->createNamedParameter($filePath),
'user_id' => $query->createNamedParameter($this->userId), 'user_id' => $query->createNamedParameter($this->userId),
'share_id' => $query->createNamedParameter($share !== null ? $share->getId(): null), 'share_id' => $query->createNamedParameter($share !== null ? $share->getId(): null),
'timestamp' => $query->createNamedParameter(time()) 'timestamp' => $query->createNamedParameter(time())
...@@ -228,9 +226,23 @@ class Manager implements IManager { ...@@ -228,9 +226,23 @@ class Manager implements IManager {
return $token; return $token;
} }
public function getFileForToken($userId, $fileId) { /**
* @param $userId
* @param $fileId
* @param null $filePath
* @return Node
* @throws NotFoundException
*/
public function getFileForToken($userId, $fileId, $filePath = null): Node {
$userFolder = $this->rootFolder->getUserFolder($userId); $userFolder = $this->rootFolder->getUserFolder($userId);
return $userFolder->getById($fileId)[0]; if ($filePath !== null) {
return $userFolder->get($filePath);
}
$files = $userFolder->getById($fileId);
if (count($files) === 0) {
throw new NotFoundException('File nound found by id ' . $fileId);
}
return $files[0];
} }
} }
...@@ -50,7 +50,7 @@ class Token implements IToken { ...@@ -50,7 +50,7 @@ class Token implements IToken {
if ($this->data['share_id'] !== null) { if ($this->data['share_id'] !== null) {
return $this->manager->getShareForToken($this->data['share_id']); return $this->manager->getShareForToken($this->data['share_id']);
} }
return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id']); return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id'], $this->data['file_path']);
} }
public function getToken(): string { public function getToken(): string {
......
...@@ -25,6 +25,7 @@ namespace OCP\DirectEditing; ...@@ -25,6 +25,7 @@ namespace OCP\DirectEditing;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\NotFoundException;
/** /**
* @since 18.0.0 * @since 18.0.0
...@@ -65,6 +66,7 @@ interface IToken { ...@@ -65,6 +66,7 @@ interface IToken {
* *
* @since 18.0.0 * @since 18.0.0
* @return File * @return File
* @throws NotFoundException
*/ */
public function getFile(): File; public function getFile(): File;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number. // when updating major/minor version number.
$OC_Version = array(18, 0, 0, 2); $OC_Version = array(18, 0, 0, 3);
// The human readable string // The human readable string
$OC_VersionString = '18.0.0 Alpha'; $OC_VersionString = '18.0.0 Alpha';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment