Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>tags/v18.0.0beta1
@@ -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', |
@@ -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', |
@@ -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(); | |||
} | |||
} | |||
} |
@@ -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 | |||
} | |||
} |
@@ -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; |
@@ -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 | |||
@@ -48,15 +42,6 @@ class FileName extends AbstractStringCheck implements IFileCheck { | |||
$this->request = $request; | |||
} | |||
/** | |||
* @param IStorage $storage | |||
* @param string $path | |||
*/ | |||
public function setFileInfo(IStorage $storage, $path) { | |||
$this->storage = $storage; | |||
$this->path = $path; | |||
} | |||
/** | |||
* @return string | |||
*/ |
@@ -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 | |||
} | |||
} |
@@ -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 | |||
@@ -67,15 +61,6 @@ class FileSystemTags implements ICheck, IFileCheck { | |||
$this->systemTagObjectMapper = $systemTagObjectMapper; | |||
} | |||
/** | |||
* @param IStorage $storage | |||
* @param string $path | |||
*/ | |||
public function setFileInfo(IStorage $storage, $path) { | |||
$this->storage = $storage; | |||
$this->path = $path; | |||
} | |||
/** | |||
* @param string $operator | |||
* @param string $value |
@@ -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 | |||
} | |||
} |
@@ -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 | |||
} | |||
} |
@@ -24,7 +24,6 @@ namespace OCA\WorkflowEngine\Check; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
use OCP\WorkflowEngine\IManager; | |||
class RequestUserAgent extends AbstractStringCheck { | |||
@@ -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 | |||
} | |||
} |
@@ -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; | |||
} |