diff options
-rw-r--r-- | apps/workflowengine/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/workflowengine/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/AFileCheck.php | 67 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/AbstractStringCheck.php | 6 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileMimeType.php | 12 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileName.php | 17 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileSize.php | 5 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileSystemTags.php | 17 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestRemoteAddress.php | 6 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestTime.php | 5 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestUserAgent.php | 1 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/UserGroupMembership.php | 6 | ||||
-rw-r--r-- | lib/public/WorkflowEngine/ICheck.php | 20 |
13 files changed, 119 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 + } } diff --git a/lib/public/WorkflowEngine/ICheck.php b/lib/public/WorkflowEngine/ICheck.php index f5586e83d51..6e9c2fc765e 100644 --- a/lib/public/WorkflowEngine/ICheck.php +++ b/lib/public/WorkflowEngine/ICheck.php @@ -70,4 +70,24 @@ interface ICheck { * @since 18.0.0 */ public function isAvailableForScope(int $scope): bool; + + /** + * Equips the check with a subject fitting the Entity. For instance, an + * entity of File will receive an instance of OCP\Files\Node, or a comment + * entity might get an IComment. + * + * The implementing check must be aware of the incoming type. + * + * If an unsupported subject is passed the implementation MAY throw an + * \UnexpectedValueException. + * + * When an implementation does not depend on a subject being passed to it, + * for example RequestTime, the implemented method SHOULD just pass, without + * any further operation. + * + * @param IEntity $entity + * @param mixed $subject + * @throws \UnexpectedValueException + */ + public function setEntitySubject(IEntity $entity, $subject): void; } |