From 849d025d093d1c80d3820901d20bf6a664c6af02 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 9 Sep 2019 16:53:59 +0200 Subject: let a dedicate service serve a stateful process * includes making ICheck not requiring any context setter * and IFileCheck extending the IEntityCheck as entity data can be handed in via Dispatcher Signed-off-by: Arthur Schiwon --- apps/workflowengine/lib/Check/AFileCheck.php | 67 ---------------------- .../lib/Check/AbstractStringCheck.php | 5 -- apps/workflowengine/lib/Check/FileSize.php | 5 -- .../lib/Check/RequestRemoteAddress.php | 5 -- apps/workflowengine/lib/Check/RequestTime.php | 5 -- apps/workflowengine/lib/Check/TFileCheck.php | 65 +++++++++++++++++++++ .../lib/Check/UserGroupMembership.php | 5 -- 7 files changed, 65 insertions(+), 92 deletions(-) delete mode 100644 apps/workflowengine/lib/Check/AFileCheck.php create mode 100644 apps/workflowengine/lib/Check/TFileCheck.php (limited to 'apps/workflowengine/lib/Check') diff --git a/apps/workflowengine/lib/Check/AFileCheck.php b/apps/workflowengine/lib/Check/AFileCheck.php deleted file mode 100644 index 45d251b1659..00000000000 --- a/apps/workflowengine/lib/Check/AFileCheck.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * @author Arthur Schiwon - * - * @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 . - * - */ - -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 ec9a1945d9c..e86ac6bec17 100644 --- a/apps/workflowengine/lib/Check/AbstractStringCheck.php +++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php @@ -24,7 +24,6 @@ namespace OCA\WorkflowEngine\Check; use OCP\IL10N; use OCP\WorkflowEngine\ICheck; -use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IManager; abstract class AbstractStringCheck implements ICheck { @@ -121,8 +120,4 @@ 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/FileSize.php b/apps/workflowengine/lib/Check/FileSize.php index 2ad4bb09e01..736a3d932fb 100644 --- a/apps/workflowengine/lib/Check/FileSize.php +++ b/apps/workflowengine/lib/Check/FileSize.php @@ -23,7 +23,6 @@ namespace OCA\WorkflowEngine\Check; use OCA\WorkflowEngine\Entity\File; -use OCP\Files\Storage\IStorage; use OCP\IL10N; use OCP\IRequest; use OCP\Util; @@ -119,8 +118,4 @@ 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/RequestRemoteAddress.php b/apps/workflowengine/lib/Check/RequestRemoteAddress.php index 0079db4b831..00029771b52 100644 --- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php +++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php @@ -25,7 +25,6 @@ namespace OCA\WorkflowEngine\Check; use OCP\IL10N; use OCP\IRequest; use OCP\WorkflowEngine\ICheck; -use OCP\WorkflowEngine\IEntity; class RequestRemoteAddress implements ICheck { @@ -171,8 +170,4 @@ 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 bf37bf3d2ba..a6ab4a961ed 100644 --- a/apps/workflowengine/lib/Check/RequestTime.php +++ b/apps/workflowengine/lib/Check/RequestTime.php @@ -25,7 +25,6 @@ namespace OCA\WorkflowEngine\Check; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IL10N; use OCP\WorkflowEngine\ICheck; -use OCP\WorkflowEngine\IEntity; class RequestTime implements ICheck { @@ -134,8 +133,4 @@ class RequestTime implements ICheck { public function supportedEntities(): array { return []; } - - public function setEntitySubject(IEntity $entity, $subject): void { - // NOOP - } } diff --git a/apps/workflowengine/lib/Check/TFileCheck.php b/apps/workflowengine/lib/Check/TFileCheck.php new file mode 100644 index 00000000000..44a39aadfde --- /dev/null +++ b/apps/workflowengine/lib/Check/TFileCheck.php @@ -0,0 +1,65 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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\IEntity; + +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/UserGroupMembership.php b/apps/workflowengine/lib/Check/UserGroupMembership.php index 55f1d017ed0..8839820050a 100644 --- a/apps/workflowengine/lib/Check/UserGroupMembership.php +++ b/apps/workflowengine/lib/Check/UserGroupMembership.php @@ -27,7 +27,6 @@ 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,8 +113,4 @@ class UserGroupMembership implements ICheck { // admin only by default return $scope === IManager::SCOPE_ADMIN; } - - public function setEntitySubject(IEntity $entity, $subject): void { - // NOOP - } } -- cgit v1.2.3