diff options
Diffstat (limited to 'apps/workflowengine/lib/Check')
-rw-r--r-- | apps/workflowengine/lib/Check/AbstractStringCheck.php | 13 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileMimeType.php | 37 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileName.php | 13 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileSize.php | 14 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/FileSystemTags.php | 59 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestRemoteAddress.php | 14 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestTime.php | 16 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestURL.php | 18 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/RequestUserAgent.php | 10 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/TFileCheck.php | 3 | ||||
-rw-r--r-- | apps/workflowengine/lib/Check/UserGroupMembership.php | 19 |
11 files changed, 81 insertions, 135 deletions
diff --git a/apps/workflowengine/lib/Check/AbstractStringCheck.php b/apps/workflowengine/lib/Check/AbstractStringCheck.php index 1c544c8c000..d92e9901365 100644 --- a/apps/workflowengine/lib/Check/AbstractStringCheck.php +++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -14,14 +15,12 @@ abstract class AbstractStringCheck implements ICheck { /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ protected $matches; - /** @var IL10N */ - protected $l; - /** * @param IL10N $l */ - public function __construct(IL10N $l) { - $this->l = $l; + public function __construct( + protected IL10N $l, + ) { } /** @@ -70,8 +69,8 @@ abstract class AbstractStringCheck implements ICheck { throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); } - if (in_array($operator, ['matches', '!matches']) && - @preg_match($value, null) === false) { + if (in_array($operator, ['matches', '!matches']) + && @preg_match($value, null) === false) { throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); } } diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php index c1e448376c9..a8dfa64528e 100644 --- a/apps/workflowengine/lib/Check/FileMimeType.php +++ b/apps/workflowengine/lib/Check/FileMimeType.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -21,21 +22,17 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { /** @var array */ protected $mimeType; - /** @var IRequest */ - protected $request; - - /** @var IMimeTypeDetector */ - protected $mimeTypeDetector; - /** * @param IL10N $l * @param IRequest $request * @param IMimeTypeDetector $mimeTypeDetector */ - public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) { + public function __construct( + IL10N $l, + protected IRequest $request, + protected IMimeTypeDetector $mimeTypeDetector, + ) { parent::__construct($l); - $this->request = $request; - $this->mimeTypeDetector = $mimeTypeDetector; } /** @@ -101,9 +98,9 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, $cacheEntry->getMimeType()); } - if ($this->storage->file_exists($this->path) && - $this->storage->filesize($this->path) && - $this->storage->instanceOfStorage(Local::class) + if ($this->storage->file_exists($this->path) + && $this->storage->filesize($this->path) + && $this->storage->instanceOfStorage(Local::class) ) { $path = $this->storage->getLocalFile($this->path); $mimeType = $this->mimeTypeDetector->detectContent($path); @@ -129,12 +126,12 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { */ protected function isWebDAVRequest() { return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( - $this->request->getPathInfo() === '/webdav' || - str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') || - $this->request->getPathInfo() === '/dav/files' || - str_starts_with($this->request->getPathInfo() ?? '', '/dav/files/') || - $this->request->getPathInfo() === '/dav/uploads' || - str_starts_with($this->request->getPathInfo() ?? '', '/dav/uploads/') + $this->request->getPathInfo() === '/webdav' + || str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') + || $this->request->getPathInfo() === '/dav/files' + || str_starts_with($this->request->getPathInfo() ?? '', '/dav/files/') + || $this->request->getPathInfo() === '/dav/uploads' + || str_starts_with($this->request->getPathInfo() ?? '', '/dav/uploads/') ); } @@ -143,8 +140,8 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { */ protected function isPublicWebDAVRequest() { return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && ( - $this->request->getPathInfo() === '/webdav' || - str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') + $this->request->getPathInfo() === '/webdav' + || str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') ); } diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php index b4c41811182..4a9d503018f 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -18,19 +18,16 @@ use OCP\WorkflowEngine\IFileCheck; class FileName extends AbstractStringCheck implements IFileCheck { use TFileCheck; - /** @var IRequest */ - protected $request; - /** @var IMountManager */ - private $mountManager; - /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) { + public function __construct( + IL10N $l, + protected IRequest $request, + private IMountManager $mountManager, + ) { parent::__construct($l); - $this->request = $request; - $this->mountManager = $mountManager; } /** diff --git a/apps/workflowengine/lib/Check/FileSize.php b/apps/workflowengine/lib/Check/FileSize.php index 51d7d38a7af..5ee03ccc9cf 100644 --- a/apps/workflowengine/lib/Check/FileSize.php +++ b/apps/workflowengine/lib/Check/FileSize.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -16,19 +17,14 @@ class FileSize implements ICheck { /** @var int */ protected $size; - /** @var IL10N */ - protected $l; - - /** @var IRequest */ - protected $request; - /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request) { - $this->l = $l; - $this->request = $request; + public function __construct( + protected IL10N $l, + protected IRequest $request, + ) { } /** diff --git a/apps/workflowengine/lib/Check/FileSystemTags.php b/apps/workflowengine/lib/Check/FileSystemTags.php index af1f1930ef0..811571f558a 100644 --- a/apps/workflowengine/lib/Check/FileSystemTags.php +++ b/apps/workflowengine/lib/Check/FileSystemTags.php @@ -1,11 +1,12 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; -use OC\Files\Storage\Wrapper\Wrapper; +use OC\Files\Storage\Wrapper\Jail; use OCA\Files_Sharing\SharedStorage; use OCA\WorkflowEngine\Entity\File; use OCP\Files\Cache\ICache; @@ -29,31 +30,13 @@ class FileSystemTags implements ICheck, IFileCheck { /** @var array */ protected $fileSystemTags; - /** @var IL10N */ - protected $l; - - /** @var ISystemTagManager */ - protected $systemTagManager; - - /** @var ISystemTagObjectMapper */ - protected $systemTagObjectMapper; - /** @var IUserSession */ - protected $userSession; - /** @var IGroupManager */ - protected $groupManager; - public function __construct( - IL10N $l, - ISystemTagManager $systemTagManager, - ISystemTagObjectMapper $systemTagObjectMapper, - IUserSession $userSession, - IGroupManager $groupManager + protected IL10N $l, + protected ISystemTagManager $systemTagManager, + protected ISystemTagObjectMapper $systemTagObjectMapper, + protected IUserSession $userSession, + protected IGroupManager $groupManager, ) { - $this->l = $l; - $this->systemTagManager = $systemTagManager; - $this->systemTagObjectMapper = $systemTagObjectMapper; - $this->userSession = $userSession; - $this->groupManager = $groupManager; } /** @@ -133,27 +116,15 @@ class FileSystemTags implements ICheck, IFileCheck { * @return int[] */ protected function getFileIds(ICache $cache, $path, $isExternalStorage) { - /** @psalm-suppress InvalidArgument */ - if ($this->storage->instanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class)) { - // Special implementation for groupfolder since all groupfolders share the same storage - // id so add the group folder id in the cache key too. - $groupFolderStorage = $this->storage; - if ($this->storage instanceof Wrapper) { - $groupFolderStorage = $this->storage->getInstanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class); - } - if ($groupFolderStorage === null) { - throw new \LogicException('Should not happen: Storage is instance of GroupFolderStorage but no group folder storage found while unwrapping.'); - } - /** - * @psalm-suppress UndefinedDocblockClass - * @psalm-suppress UndefinedInterfaceMethod - */ - $cacheId = $cache->getNumericStorageId() . '/' . $groupFolderStorage->getFolderId(); + $cacheId = $cache->getNumericStorageId(); + if ($this->storage->instanceOfStorage(Jail::class)) { + $absolutePath = $this->storage->getUnjailedPath($path); } else { - $cacheId = $cache->getNumericStorageId(); + $absolutePath = $path; } - if (isset($this->fileIds[$cacheId][$path])) { - return $this->fileIds[$cacheId][$path]; + + if (isset($this->fileIds[$cacheId][$absolutePath])) { + return $this->fileIds[$cacheId][$absolutePath]; } $parentIds = []; @@ -168,7 +139,7 @@ class FileSystemTags implements ICheck, IFileCheck { $parentIds[] = $fileId; } - $this->fileIds[$cacheId][$path] = $parentIds; + $this->fileIds[$cacheId][$absolutePath] = $parentIds; return $parentIds; } diff --git a/apps/workflowengine/lib/Check/RequestRemoteAddress.php b/apps/workflowengine/lib/Check/RequestRemoteAddress.php index 909b26c74d6..b6f8fef5aed 100644 --- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php +++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -11,19 +12,14 @@ use OCP\WorkflowEngine\ICheck; class RequestRemoteAddress implements ICheck { - /** @var IL10N */ - protected $l; - - /** @var IRequest */ - protected $request; - /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request) { - $this->l = $l; - $this->request = $request; + public function __construct( + protected IL10N $l, + protected IRequest $request, + ) { } /** diff --git a/apps/workflowengine/lib/Check/RequestTime.php b/apps/workflowengine/lib/Check/RequestTime.php index 3bb1dba9d93..a49986652b8 100644 --- a/apps/workflowengine/lib/Check/RequestTime.php +++ b/apps/workflowengine/lib/Check/RequestTime.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -16,18 +17,13 @@ class RequestTime implements ICheck { /** @var bool[] */ protected $cachedResults; - /** @var IL10N */ - protected $l; - - /** @var ITimeFactory */ - protected $timeFactory; - /** * @param ITimeFactory $timeFactory */ - public function __construct(IL10N $l, ITimeFactory $timeFactory) { - $this->l = $l; - $this->timeFactory = $timeFactory; + public function __construct( + protected IL10N $l, + protected ITimeFactory $timeFactory, + ) { } /** @@ -67,7 +63,7 @@ class RequestTime implements ICheck { [$hour1, $minute1] = explode(':', $time1); $date1 = new \DateTime('now', new \DateTimeZone($timezone1)); $date1->setTimestamp($currentTimestamp); - $date1->setTime($hour1, $minute1); + $date1->setTime((int)$hour1, (int)$minute1); return $date1->getTimestamp(); } diff --git a/apps/workflowengine/lib/Check/RequestURL.php b/apps/workflowengine/lib/Check/RequestURL.php index 43123bddbe9..fb2ac7e8fd5 100644 --- a/apps/workflowengine/lib/Check/RequestURL.php +++ b/apps/workflowengine/lib/Check/RequestURL.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -14,16 +15,15 @@ class RequestURL extends AbstractStringCheck { /** @var ?string */ protected $url; - /** @var IRequest */ - protected $request; - /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request) { + public function __construct( + IL10N $l, + protected IRequest $request, + ) { parent::__construct($l); - $this->request = $request; } /** @@ -71,10 +71,10 @@ class RequestURL extends AbstractStringCheck { return false; } return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( - $this->request->getPathInfo() === '/webdav' || - str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') || - $this->request->getPathInfo() === '/dav/files' || - str_starts_with($this->request->getPathInfo() ?? '', '/dav/files/') + $this->request->getPathInfo() === '/webdav' + || str_starts_with($this->request->getPathInfo() ?? '', '/webdav/') + || $this->request->getPathInfo() === '/dav/files' + || str_starts_with($this->request->getPathInfo() ?? '', '/dav/files/') ); } } diff --git a/apps/workflowengine/lib/Check/RequestUserAgent.php b/apps/workflowengine/lib/Check/RequestUserAgent.php index 2ae630394fb..572ef567074 100644 --- a/apps/workflowengine/lib/Check/RequestUserAgent.php +++ b/apps/workflowengine/lib/Check/RequestUserAgent.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -10,16 +11,15 @@ use OCP\IRequest; class RequestUserAgent extends AbstractStringCheck { - /** @var IRequest */ - protected $request; - /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request) { + public function __construct( + IL10N $l, + protected IRequest $request, + ) { parent::__construct($l); - $this->request = $request; } /** diff --git a/apps/workflowengine/lib/Check/TFileCheck.php b/apps/workflowengine/lib/Check/TFileCheck.php index 0304a76bd21..a514352e047 100644 --- a/apps/workflowengine/lib/Check/TFileCheck.php +++ b/apps/workflowengine/lib/Check/TFileCheck.php @@ -11,6 +11,7 @@ namespace OCA\WorkflowEngine\Check; use OCA\WorkflowEngine\AppInfo\Application; use OCA\WorkflowEngine\Entity\File; use OCP\Files\Node; +use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; use OCP\WorkflowEngine\IEntity; @@ -37,7 +38,7 @@ trait TFileCheck { } /** - * @throws \OCP\Files\NotFoundException + * @throws NotFoundException */ public function setEntitySubject(IEntity $entity, $subject): void { if ($entity instanceof File) { diff --git a/apps/workflowengine/lib/Check/UserGroupMembership.php b/apps/workflowengine/lib/Check/UserGroupMembership.php index 1c2e535b346..690f9974a49 100644 --- a/apps/workflowengine/lib/Check/UserGroupMembership.php +++ b/apps/workflowengine/lib/Check/UserGroupMembership.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -20,24 +21,16 @@ class UserGroupMembership implements ICheck { /** @var string[] */ protected $cachedGroupMemberships; - /** @var IUserSession */ - protected $userSession; - - /** @var IGroupManager */ - protected $groupManager; - - /** @var IL10N */ - protected $l; - /** * @param IUserSession $userSession * @param IGroupManager $groupManager * @param IL10N $l */ - public function __construct(IUserSession $userSession, IGroupManager $groupManager, IL10N $l) { - $this->userSession = $userSession; - $this->groupManager = $groupManager; - $this->l = $l; + public function __construct( + protected IUserSession $userSession, + protected IGroupManager $groupManager, + protected IL10N $l, + ) { } /** |