diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-09-09 16:04:12 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-09-09 22:56:05 +0200 |
commit | 4cd931fcc6bb7f794fd14ddb75c7867823449e79 (patch) | |
tree | 0d2a6d1083dc865407cbe9cd891c977c0e4c9f06 /apps | |
parent | fd2de58503a3c915cf178385db3e9962845719c4 (diff) | |
download | nextcloud-server-4cd931fcc6bb7f794fd14ddb75c7867823449e79.tar.gz nextcloud-server-4cd931fcc6bb7f794fd14ddb75c7867823449e79.zip |
require IChecks to receive entity context
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps')
12 files changed, 99 insertions, 45 deletions
diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php index 4dab03642dd..6264358788c 100644 --- a/apps/workflowengine/composer/composer/autoload_classmap.php +++ b/apps/workflowengine/composer/composer/autoload_classmap.php @@ -16,6 +16,7 @@ return array( 'OCA\\WorkflowEngine\\Check\\RequestTime' => $baseDir . '/../lib/Check/RequestTime.php', 'OCA\\WorkflowEngine\\Check\\RequestURL' => $baseDir . '/../lib/Check/RequestURL.php', 'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => $baseDir . '/../lib/Check/RequestUserAgent.php', + 'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/AFileCheck.php', 'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php', 'OCA\\WorkflowEngine\\Command\\Index' => $baseDir . '/../lib/Command/Index.php', 'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => $baseDir . '/../lib/Controller/AWorkflowController.php', diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php index 38b1a5b0e76..cd370986f15 100644 --- a/apps/workflowengine/composer/composer/autoload_static.php +++ b/apps/workflowengine/composer/composer/autoload_static.php @@ -31,6 +31,7 @@ class ComposerStaticInitWorkflowEngine 'OCA\\WorkflowEngine\\Check\\RequestTime' => __DIR__ . '/..' . '/../lib/Check/RequestTime.php', 'OCA\\WorkflowEngine\\Check\\RequestURL' => __DIR__ . '/..' . '/../lib/Check/RequestURL.php', 'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => __DIR__ . '/..' . '/../lib/Check/RequestUserAgent.php', + 'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/AFileCheck.php', 'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php', 'OCA\\WorkflowEngine\\Command\\Index' => __DIR__ . '/..' . '/../lib/Command/Index.php', 'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => __DIR__ . '/..' . '/../lib/Controller/AWorkflowController.php', diff --git a/apps/workflowengine/lib/Check/AFileCheck.php b/apps/workflowengine/lib/Check/AFileCheck.php new file mode 100644 index 00000000000..45d251b1659 --- /dev/null +++ b/apps/workflowengine/lib/Check/AFileCheck.php @@ -0,0 +1,67 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @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\WorkflowEngine\Check; + +use OCA\WorkflowEngine\AppInfo\Application; +use OCA\WorkflowEngine\Entity\File; +use OCP\Files\Node; +use OCP\Files\Storage\IStorage; +use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; +use OCP\WorkflowEngine\IFileCheck; + +trait TFileCheck { + /** @var IStorage */ + protected $storage; + + /** @var string */ + protected $path; + + /** + * @param IStorage $storage + * @param string $path + * @since 18.0.0 + */ + public function setFileInfo(IStorage $storage, $path) { + $this->storage = $storage; + $this->path = $path; + } + + /** + * @throws \OCP\Files\NotFoundException + */ + public function setEntitySubject(IEntity $entity, $subject): void { + if ($entity instanceof File) { + if (!$subject instanceof Node) { + throw new \UnexpectedValueException( + 'Expected Node subject for File entity, got {class}', + ['app' => Application::APP_ID, 'class' => get_class($subject)] + ); + } + $this->storage = $subject->getStorage(); + $this->path = $subject->getPath(); + } + } +} diff --git a/apps/workflowengine/lib/Check/AbstractStringCheck.php b/apps/workflowengine/lib/Check/AbstractStringCheck.php index edd983ba699..ec9a1945d9c 100644 --- a/apps/workflowengine/lib/Check/AbstractStringCheck.php +++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php @@ -22,9 +22,9 @@ namespace OCA\WorkflowEngine\Check; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IManager; abstract class AbstractStringCheck implements ICheck { @@ -121,4 +121,8 @@ abstract class AbstractStringCheck implements ICheck { $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject); return $this->matches[$patternHash][$subjectHash]; } + + public function setEntitySubject(IEntity $entity, $subject): void { + // Noop + } } diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php index 52fc54fc859..92375d4d3cd 100644 --- a/apps/workflowengine/lib/Check/FileMimeType.php +++ b/apps/workflowengine/lib/Check/FileMimeType.php @@ -30,6 +30,9 @@ use OCP\IRequest; use OCP\WorkflowEngine\IFileCheck; class FileMimeType extends AbstractStringCheck implements IFileCheck { + use TFileCheck { + setFileInfo as _setFileInfo; + } /** @var array */ protected $mimeType; @@ -40,12 +43,6 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { /** @var IMimeTypeDetector */ protected $mimeTypeDetector; - /** @var IStorage */ - protected $storage; - - /** @var string */ - protected $path; - /** * @param IL10N $l * @param IRequest $request @@ -62,8 +59,7 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { * @param string $path */ public function setFileInfo(IStorage $storage, $path) { - $this->storage = $storage; - $this->path = $path; + $this->_setFileInfo($storage, $path); if (!isset($this->mimeType[$this->storage->getId()][$this->path]) || $this->mimeType[$this->storage->getId()][$this->path] === '') { $this->mimeType[$this->storage->getId()][$this->path] = null; diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php index 76c48b7955e..62ee601980b 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -23,22 +23,16 @@ declare(strict_types=1); namespace OCA\WorkflowEngine\Check; use OCA\WorkflowEngine\Entity\File; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\IRequest; use OCP\WorkflowEngine\IFileCheck; class FileName extends AbstractStringCheck implements IFileCheck { + use TFileCheck; /** @var IRequest */ protected $request; - /** @var IStorage */ - protected $storage; - - /** @var string */ - protected $path; - /** * @param IL10N $l * @param IRequest $request @@ -49,15 +43,6 @@ class FileName extends AbstractStringCheck implements IFileCheck { } /** - * @param IStorage $storage - * @param string $path - */ - public function setFileInfo(IStorage $storage, $path) { - $this->storage = $storage; - $this->path = $path; - } - - /** * @return string */ protected function getActualValue(): string { diff --git a/apps/workflowengine/lib/Check/FileSize.php b/apps/workflowengine/lib/Check/FileSize.php index ac1896c6057..2ad4bb09e01 100644 --- a/apps/workflowengine/lib/Check/FileSize.php +++ b/apps/workflowengine/lib/Check/FileSize.php @@ -28,6 +28,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\Util; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; class FileSize implements ICheck { @@ -118,4 +119,8 @@ class FileSize implements ICheck { public function isAvailableForScope(int $scope): bool { return true; } + + public function setEntitySubject(IEntity $entity, $subject): void { + // NOOP + } } diff --git a/apps/workflowengine/lib/Check/FileSystemTags.php b/apps/workflowengine/lib/Check/FileSystemTags.php index 41b657d53b0..e7e114881ad 100644 --- a/apps/workflowengine/lib/Check/FileSystemTags.php +++ b/apps/workflowengine/lib/Check/FileSystemTags.php @@ -25,7 +25,6 @@ namespace OCA\WorkflowEngine\Check; use OCA\WorkflowEngine\Entity\File; use OCP\Files\Cache\ICache; use OCP\Files\IHomeStorage; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; @@ -34,6 +33,7 @@ use OCP\WorkflowEngine\ICheck; use OCP\WorkflowEngine\IFileCheck; class FileSystemTags implements ICheck, IFileCheck { + use TFileCheck; /** @var array */ protected $fileIds; @@ -50,12 +50,6 @@ class FileSystemTags implements ICheck, IFileCheck { /** @var ISystemTagObjectMapper */ protected $systemTagObjectMapper; - /** @var IStorage */ - protected $storage; - - /** @var string */ - protected $path; - /** * @param IL10N $l * @param ISystemTagManager $systemTagManager @@ -68,15 +62,6 @@ class FileSystemTags implements ICheck, IFileCheck { } /** - * @param IStorage $storage - * @param string $path - */ - public function setFileInfo(IStorage $storage, $path) { - $this->storage = $storage; - $this->path = $path; - } - - /** * @param string $operator * @param string $value * @return bool diff --git a/apps/workflowengine/lib/Check/RequestRemoteAddress.php b/apps/workflowengine/lib/Check/RequestRemoteAddress.php index 28e3bd4be09..0079db4b831 100644 --- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php +++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php @@ -22,10 +22,10 @@ namespace OCA\WorkflowEngine\Check; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\IRequest; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; class RequestRemoteAddress implements ICheck { @@ -171,4 +171,8 @@ class RequestRemoteAddress implements ICheck { public function isAvailableForScope(int $scope): bool { return true; } + + public function setEntitySubject(IEntity $entity, $subject): void { + // NOOP + } } diff --git a/apps/workflowengine/lib/Check/RequestTime.php b/apps/workflowengine/lib/Check/RequestTime.php index 523d251789a..bf37bf3d2ba 100644 --- a/apps/workflowengine/lib/Check/RequestTime.php +++ b/apps/workflowengine/lib/Check/RequestTime.php @@ -23,9 +23,9 @@ namespace OCA\WorkflowEngine\Check; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; class RequestTime implements ICheck { @@ -135,4 +135,7 @@ class RequestTime implements ICheck { return []; } + public function setEntitySubject(IEntity $entity, $subject): void { + // NOOP + } } diff --git a/apps/workflowengine/lib/Check/RequestUserAgent.php b/apps/workflowengine/lib/Check/RequestUserAgent.php index 1abb56bbe2d..ddc222833dd 100644 --- a/apps/workflowengine/lib/Check/RequestUserAgent.php +++ b/apps/workflowengine/lib/Check/RequestUserAgent.php @@ -24,7 +24,6 @@ namespace OCA\WorkflowEngine\Check; use OCP\IL10N; use OCP\IRequest; -use OCP\WorkflowEngine\IManager; class RequestUserAgent extends AbstractStringCheck { diff --git a/apps/workflowengine/lib/Check/UserGroupMembership.php b/apps/workflowengine/lib/Check/UserGroupMembership.php index e9518733f9b..55f1d017ed0 100644 --- a/apps/workflowengine/lib/Check/UserGroupMembership.php +++ b/apps/workflowengine/lib/Check/UserGroupMembership.php @@ -22,12 +22,12 @@ namespace OCA\WorkflowEngine\Check; -use OCP\Files\Storage\IStorage; use OCP\IGroupManager; use OCP\IL10N; use OCP\IUser; use OCP\IUserSession; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IManager; class UserGroupMembership implements ICheck { @@ -114,4 +114,8 @@ class UserGroupMembership implements ICheck { // admin only by default return $scope === IManager::SCOPE_ADMIN; } + + public function setEntitySubject(IEntity $entity, $subject): void { + // NOOP + } } |