diff options
-rw-r--r-- | apps/dav/lib/Files/FileSearchBackend.php | 4 | ||||
-rw-r--r-- | apps/files/lib/Controller/DirectEditingController.php | 4 | ||||
-rw-r--r-- | core/Migrations/Version18000Date20191204114856.php | 66 | ||||
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 34 | ||||
-rw-r--r-- | lib/private/DirectEditing/Token.php | 2 | ||||
-rw-r--r-- | lib/private/Hooks/BasicEmitter.php | 3 | ||||
-rw-r--r-- | lib/private/Hooks/Emitter.php | 1 | ||||
-rw-r--r-- | lib/private/Hooks/PublicEmitter.php | 3 | ||||
-rw-r--r-- | lib/private/Security/Normalizer/IpAddress.php | 4 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/private/legacy/hook.php | 6 | ||||
-rw-r--r-- | lib/public/DirectEditing/IToken.php | 2 |
14 files changed, 116 insertions, 16 deletions
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 5cbb30a2706..751580eabfc 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -275,6 +275,7 @@ class FileSearchBackend implements ISearchBackend { // TODO offset $limit = $query->limit; $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); + $offset = 0; $limitHome = false; $ownerProp = $this->extractWhereValue($query->where, FilesPlugin::OWNER_ID_PROPERTYNAME, Operator::OPERATION_EQUAL); @@ -284,12 +285,13 @@ class FileSearchBackend implements ISearchBackend { } else { throw new \InvalidArgumentException("Invalid search value for '{http://owncloud.org/ns}owner-id', only the current user id is allowed"); } + $offset = $limit->firstResult; } return new SearchQuery( $this->transformSearchOperation($query->where), (int)$limit->maxResults, - 0, + $offset, $orders, $this->user, $limitHome diff --git a/apps/files/lib/Controller/DirectEditingController.php b/apps/files/lib/Controller/DirectEditingController.php index e8a00981327..b19d0f3ea1d 100644 --- a/apps/files/lib/Controller/DirectEditingController.php +++ b/apps/files/lib/Controller/DirectEditingController.php @@ -96,11 +96,11 @@ class DirectEditingController extends OCSController { /** * @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)); try { - $token = $this->directEditingManager->open($fileId, $editorId); + $token = $this->directEditingManager->open($path, $editorId); return new DataResponse([ 'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token]) ]); diff --git a/core/Migrations/Version18000Date20191204114856.php b/core/Migrations/Version18000Date20191204114856.php new file mode 100644 index 00000000000..fc2edadb18f --- /dev/null +++ b/core/Migrations/Version18000Date20191204114856.php @@ -0,0 +1,66 @@ +<?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; + } + +} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b3e12e557d5..8df7c5a26f9 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -819,6 +819,7 @@ return array( 'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => $baseDir . '/core/Migrations/Version18000Date20190920085628.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\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 6ca4763440d..1659953433a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -848,6 +848,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20190920085628.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\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index e9bd6f2933c..fcaaf9e0303 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -37,6 +37,7 @@ use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\IRootFolder; +use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IDBConnection; use OCP\IUserSession; @@ -104,25 +105,21 @@ class Manager implements IManager { foreach ($creators as $creator) { if ($creator->getId() === $creatorId) { $creator->create($file, $creatorId, $templateId); - return $this->createToken($editorId, $file); + return $this->createToken($editorId, $file, $path); } } throw new \RuntimeException('No creator found'); } - public function open(int $fileId, 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(); - } + public function open(string $filePath, string $editorId = null): string { /** @var File $file */ - $file = $file[0]; + $file = $this->rootFolder->getUserFolder($this->userId)->get($filePath); if ($editorId === null) { $editorId = $this->findEditorForFile($file); } - return $this->createToken($editorId, $file); + return $this->createToken($editorId, $file, $filePath); } private function findEditorForFile(File $file) { @@ -213,7 +210,7 @@ class Manager implements IManager { \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); $query = $this->connection->getQueryBuilder(); $query->insert(self::TABLE_TOKENS) @@ -221,6 +218,7 @@ class Manager implements IManager { 'token' => $query->createNamedParameter($token), 'editor_id' => $query->createNamedParameter($editorId), 'file_id' => $query->createNamedParameter($file->getId()), + 'file_path' => $query->createNamedParameter($filePath), 'user_id' => $query->createNamedParameter($this->userId), 'share_id' => $query->createNamedParameter($share !== null ? $share->getId(): null), 'timestamp' => $query->createNamedParameter(time()) @@ -229,9 +227,23 @@ class Manager implements IManager { 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); - 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]; } } diff --git a/lib/private/DirectEditing/Token.php b/lib/private/DirectEditing/Token.php index c991ebef9db..add6f5b471c 100644 --- a/lib/private/DirectEditing/Token.php +++ b/lib/private/DirectEditing/Token.php @@ -50,7 +50,7 @@ class Token implements IToken { if ($this->data['share_id'] !== null) { 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 { diff --git a/lib/private/Hooks/BasicEmitter.php b/lib/private/Hooks/BasicEmitter.php index 529f3724d32..37c38b4be1d 100644 --- a/lib/private/Hooks/BasicEmitter.php +++ b/lib/private/Hooks/BasicEmitter.php @@ -23,6 +23,9 @@ namespace OC\Hooks; +/** + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher + */ abstract class BasicEmitter implements Emitter { use EmitterTrait; } diff --git a/lib/private/Hooks/Emitter.php b/lib/private/Hooks/Emitter.php index fbe1a8eaf1f..65c99f2b94d 100644 --- a/lib/private/Hooks/Emitter.php +++ b/lib/private/Hooks/Emitter.php @@ -30,6 +30,7 @@ namespace OC\Hooks; * interface for all classes that are able to emit events * * @package OC\Hooks + * @deprecated 18.0.0 use events and the \OCP\EventDispatcher\IEventDispatcher service */ interface Emitter { /** diff --git a/lib/private/Hooks/PublicEmitter.php b/lib/private/Hooks/PublicEmitter.php index 4101fd12349..abb4dedd667 100644 --- a/lib/private/Hooks/PublicEmitter.php +++ b/lib/private/Hooks/PublicEmitter.php @@ -24,6 +24,9 @@ namespace OC\Hooks; +/** + * @deprecated 18.0.0 use events and the \OCP\EventDispatcher\IEventDispatcher service + */ class PublicEmitter extends BasicEmitter { /** * @param string $scope diff --git a/lib/private/Security/Normalizer/IpAddress.php b/lib/private/Security/Normalizer/IpAddress.php index 3bac6d8b103..8fb7b1003c4 100644 --- a/lib/private/Security/Normalizer/IpAddress.php +++ b/lib/private/Security/Normalizer/IpAddress.php @@ -75,6 +75,10 @@ class IpAddress { if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1] $ip = substr($ip, 1, strlen($ip) - 2); } + $pos = strpos($ip, '%'); // if there is an explicit interface added to the IP, e.g. fe80::ae2d:d1e7:fe1e:9a8d%enp2s0 + if ($pos !== false) { + $ip = substr($ip, 0, $pos-1); + } $binary = \inet_pton($ip); for ($i = 128; $i > $maskBits; $i -= 8) { $j = \intdiv($i, 8) - 1; diff --git a/lib/private/Server.php b/lib/private/Server.php index c6ff6691998..e7fb32ba1e5 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1914,6 +1914,7 @@ class Server extends ServerContainer implements IServerContainer { * * @return EventDispatcherInterface * @since 8.2.0 + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher */ public function getEventDispatcher() { return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); diff --git a/lib/private/legacy/hook.php b/lib/private/legacy/hook.php index 0d413a11de7..78060d76e0d 100644 --- a/lib/private/legacy/hook.php +++ b/lib/private/legacy/hook.php @@ -28,7 +28,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -class OC_Hook{ + +/** + * @deprecated 18.0.0 use events and the \OCP\EventDispatcher\IEventDispatcher service + */ +class OC_Hook { public static $thrownExceptions = []; static private $registered = array(); diff --git a/lib/public/DirectEditing/IToken.php b/lib/public/DirectEditing/IToken.php index bdde5bbe949..416b2ccb807 100644 --- a/lib/public/DirectEditing/IToken.php +++ b/lib/public/DirectEditing/IToken.php @@ -25,6 +25,7 @@ namespace OCP\DirectEditing; use OCP\Files\File; +use OCP\Files\NotFoundException; /** * @since 18.0.0 @@ -65,6 +66,7 @@ interface IToken { * * @since 18.0.0 * @return File + * @throws NotFoundException */ public function getFile(): File; |