diff options
Diffstat (limited to 'apps/workflowengine/lib')
33 files changed, 390 insertions, 1117 deletions
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index fb5514fecef..93b0ca49260 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -1,33 +1,12 @@ <?php + /** - * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\AppInfo; use Closure; -use OCA\WorkflowEngine\Controller\RequestTime; use OCA\WorkflowEngine\Helper\LogContext; use OCA\WorkflowEngine\Listener\LoadAdditionalSettingsScriptsListener; use OCA\WorkflowEngine\Manager; @@ -36,16 +15,14 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\QueryException; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; -use OCP\IServerContainer; use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent; use OCP\WorkflowEngine\IEntity; -use OCP\WorkflowEngine\IEntityCompat; use OCP\WorkflowEngine\IOperation; -use OCP\WorkflowEngine\IOperationCompat; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { public const APP_ID = 'workflowengine'; @@ -55,7 +32,6 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - $context->registerServiceAlias('RequestTimeController', RequestTime::class); $context->registerEventListener( LoadSettingsScriptsEvent::class, LoadAdditionalSettingsScriptsListener::class, @@ -68,24 +44,24 @@ class Application extends App implements IBootstrap { } private function registerRuleListeners(IEventDispatcher $dispatcher, - IServerContainer $container, - ILogger $logger): void { + ContainerInterface $container, + LoggerInterface $logger): void { /** @var Manager $manager */ - $manager = $container->query(Manager::class); + $manager = $container->get(Manager::class); $configuredEvents = $manager->getAllConfiguredEvents(); foreach ($configuredEvents as $operationClass => $events) { foreach ($events as $entityClass => $eventNames) { - array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { + array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass): void { $dispatcher->addListener( $eventName, - function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { + function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass): void { $ruleMatcher = $manager->getRuleMatcher(); try { /** @var IEntity $entity */ - $entity = $container->query($entityClass); + $entity = $container->get($entityClass); /** @var IOperation $operation */ - $operation = $container->query($operationClass); + $operation = $container->get($operationClass); $ruleMatcher->setEventName($eventName); $ruleMatcher->setEntity($entity); @@ -98,16 +74,12 @@ class Application extends App implements IBootstrap { ->setEventName($eventName); /** @var Logger $flowLogger */ - $flowLogger = $container->query(Logger::class); + $flowLogger = $container->get(Logger::class); $flowLogger->logEventInit($ctx); if ($event instanceof Event) { $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); $operation->onEvent($eventName, $event, $ruleMatcher); - } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { - // TODO: Remove this block (and the compat classes) in the first major release in 2023 - $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); - $operation->onEventCompat($eventName, $event, $ruleMatcher); } else { $logger->debug( 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', @@ -121,8 +93,8 @@ class Application extends App implements IBootstrap { ); } $flowLogger->logEventDone($ctx); - } catch (QueryException $e) { - // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now + } catch (ContainerExceptionInterface $e) { + // Ignore query exceptions since they might occur when an entity/operation were set up before by an app that is disabled now } } ); diff --git a/apps/workflowengine/lib/BackgroundJobs/Rotate.php b/apps/workflowengine/lib/BackgroundJobs/Rotate.php index ee83f4821f1..d7984b1226a 100644 --- a/apps/workflowengine/lib/BackgroundJobs/Rotate.php +++ b/apps/workflowengine/lib/BackgroundJobs/Rotate.php @@ -1,32 +1,17 @@ <?php + /** - * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\BackgroundJobs; +use OCA\WorkflowEngine\AppInfo\Application; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; -use OCA\WorkflowEngine\AppInfo\Application; +use OCP\IConfig; use OCP\Log\RotationTrait; +use OCP\Server; class Rotate extends TimedJob { use RotationTrait; @@ -37,7 +22,7 @@ class Rotate extends TimedJob { } protected function run($argument) { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log'; $this->filePath = trim((string)$config->getAppValue(Application::APP_ID, 'logfile', $default)); diff --git a/apps/workflowengine/lib/Check/AbstractStringCheck.php b/apps/workflowengine/lib/Check/AbstractStringCheck.php index 26047f90d50..d92e9901365 100644 --- a/apps/workflowengine/lib/Check/AbstractStringCheck.php +++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php @@ -1,26 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -33,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, + ) { } /** @@ -89,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 991d7ebc739..a8dfa64528e 100644 --- a/apps/workflowengine/lib/Check/FileMimeType.php +++ b/apps/workflowengine/lib/Check/FileMimeType.php @@ -1,28 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -42,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; } /** @@ -107,13 +83,7 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { * @return bool */ public function executeCheck($operator, $value) { - $actualValue = $this->getActualValue(); - $plainMimetypeResult = $this->executeStringCheck($operator, $value, $actualValue); - if ($actualValue === 'httpd/unix-directory') { - return $plainMimetypeResult; - } - $detectMimetypeBasedOnFilenameResult = $this->executeStringCheck($operator, $value, $this->mimeTypeDetector->detectPath($this->path)); - return $plainMimetypeResult || $detectMimetypeBasedOnFilenameResult; + return $this->executeStringCheck($operator, $value, $this->getActualValue()); } /** @@ -128,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); @@ -156,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' || - strpos($this->request->getPathInfo(), '/webdav/') === 0 || - $this->request->getPathInfo() === '/dav/files' || - strpos($this->request->getPathInfo(), '/dav/files/') === 0 || - $this->request->getPathInfo() === '/dav/uploads' || - strpos($this->request->getPathInfo(), '/dav/uploads/') === 0 + $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/') ); } @@ -170,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' || - strpos($this->request->getPathInfo(), '/webdav/') === 0 + $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 32df51ebfac..4a9d503018f 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018 Daniel Kesselberg <mail@danielkesselberg.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author szaimen <szaimen@e.mail.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/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -37,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 7271147e834..5ee03ccc9cf 100644 --- a/apps/workflowengine/lib/Check/FileSize.php +++ b/apps/workflowengine/lib/Check/FileSize.php @@ -1,26 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -35,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 008f47eca78..811571f558a 100644 --- a/apps/workflowengine/lib/Check/FileSystemTags.php +++ b/apps/workflowengine/lib/Check/FileSystemTags.php @@ -1,42 +1,25 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Richard Steinmetz <richard@steinmetz.cloud> - * - * @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/>. - * + * 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\Jail; use OCA\Files_Sharing\SharedStorage; use OCA\WorkflowEngine\Entity\File; use OCP\Files\Cache\ICache; use OCP\Files\IHomeStorage; +use OCP\IGroupManager; use OCP\IL10N; +use OCP\IUser; +use OCP\IUserSession; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\SystemTag\TagNotFoundException; use OCP\WorkflowEngine\ICheck; use OCP\WorkflowEngine\IFileCheck; -use OC\Files\Storage\Wrapper\Wrapper; class FileSystemTags implements ICheck, IFileCheck { use TFileCheck; @@ -47,24 +30,13 @@ class FileSystemTags implements ICheck, IFileCheck { /** @var array */ protected $fileSystemTags; - /** @var IL10N */ - protected $l; - - /** @var ISystemTagManager */ - protected $systemTagManager; - - /** @var ISystemTagObjectMapper */ - protected $systemTagObjectMapper; - - /** - * @param IL10N $l - * @param ISystemTagManager $systemTagManager - * @param ISystemTagObjectMapper $systemTagObjectMapper - */ - public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISystemTagObjectMapper $systemTagObjectMapper) { - $this->l = $l; - $this->systemTagManager = $systemTagManager; - $this->systemTagObjectMapper = $systemTagObjectMapper; + public function __construct( + protected IL10N $l, + protected ISystemTagManager $systemTagManager, + protected ISystemTagObjectMapper $systemTagObjectMapper, + protected IUserSession $userSession, + protected IGroupManager $groupManager, + ) { } /** @@ -88,7 +60,18 @@ class FileSystemTags implements ICheck, IFileCheck { } try { - $this->systemTagManager->getTagsByIds($value); + $tags = $this->systemTagManager->getTagsByIds($value); + + $user = $this->userSession->getUser(); + $isAdmin = $user instanceof IUser && $this->groupManager->isAdmin($user->getUID()); + + if (!$isAdmin) { + foreach ($tags as $tag) { + if (!$tag->isUserVisible()) { + throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 4); + } + } + } } catch (TagNotFoundException $e) { throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 2); } catch (\InvalidArgumentException $e) { @@ -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 474599a8642..b6f8fef5aed 100644 --- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php +++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php @@ -1,28 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author J0WI <J0WI@users.noreply.github.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -32,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 be28f8ead15..a49986652b8 100644 --- a/apps/workflowengine/lib/Check/RequestTime.php +++ b/apps/workflowengine/lib/Check/RequestTime.php @@ -1,27 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -36,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, + ) { } /** @@ -87,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 73e6a2e6ce6..fb2ac7e8fd5 100644 --- a/apps/workflowengine/lib/Check/RequestURL.php +++ b/apps/workflowengine/lib/Check/RequestURL.php @@ -1,25 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -32,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; } /** @@ -89,10 +71,10 @@ class RequestURL extends AbstractStringCheck { return false; } return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( - $this->request->getPathInfo() === '/webdav' || - strpos($this->request->getPathInfo(), '/webdav/') === 0 || - $this->request->getPathInfo() === '/dav/files' || - strpos($this->request->getPathInfo(), '/dav/files/') === 0 + $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 e8ca3ddfbc9..572ef567074 100644 --- a/apps/workflowengine/lib/Check/RequestUserAgent.php +++ b/apps/workflowengine/lib/Check/RequestUserAgent.php @@ -1,26 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -29,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 561cf012ff7..a514352e047 100644 --- a/apps/workflowengine/lib/Check/TFileCheck.php +++ b/apps/workflowengine/lib/Check/TFileCheck.php @@ -3,32 +3,15 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ 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; @@ -55,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 4ca073b8e5b..690f9974a49 100644 --- a/apps/workflowengine/lib/Check/UserGroupMembership.php +++ b/apps/workflowengine/lib/Check/UserGroupMembership.php @@ -1,26 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de> - * - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Check; @@ -39,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, + ) { } /** diff --git a/apps/workflowengine/lib/Command/Index.php b/apps/workflowengine/lib/Command/Index.php index 4f418b4ffc7..1fb8cb416b0 100644 --- a/apps/workflowengine/lib/Command/Index.php +++ b/apps/workflowengine/lib/Command/Index.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Command; @@ -36,11 +18,9 @@ use Symfony\Component\Console\Output\OutputInterface; class Index extends Command { - /** @var Manager */ - private $manager; - - public function __construct(Manager $manager) { - $this->manager = $manager; + public function __construct( + private Manager $manager, + ) { parent::__construct(); } diff --git a/apps/workflowengine/lib/Controller/AWorkflowController.php b/apps/workflowengine/lib/Controller/AWorkflowController.php index 77e50526092..6395d0d98f6 100644 --- a/apps/workflowengine/lib/Controller/AWorkflowController.php +++ b/apps/workflowengine/lib/Controller/AWorkflowController.php @@ -3,33 +3,15 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author blizzz <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Controller; use Doctrine\DBAL\Exception; use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Manager; +use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; @@ -40,22 +22,13 @@ use Psr\Log\LoggerInterface; abstract class AWorkflowController extends OCSController { - /** @var Manager */ - protected $manager; - - /** @var LoggerInterface */ - private $logger; - public function __construct( $appName, IRequest $request, - Manager $manager, - LoggerInterface $logger + protected Manager $manager, + private LoggerInterface $logger, ) { parent::__construct($appName, $request); - - $this->manager = $manager; - $this->logger = $logger; } /** @@ -103,13 +76,14 @@ abstract class AWorkflowController extends OCSController { * @throws OCSForbiddenException * @throws OCSException */ + #[PasswordConfirmationRequired] public function create( string $class, string $name, array $checks, string $operation, string $entity, - array $events + array $events, ): DataResponse { $context = $this->getScopeContext(); try { @@ -131,13 +105,14 @@ abstract class AWorkflowController extends OCSController { * @throws OCSForbiddenException * @throws OCSException */ + #[PasswordConfirmationRequired] public function update( int $id, string $name, array $checks, string $operation, string $entity, - array $events + array $events, ): DataResponse { try { $context = $this->getScopeContext(); @@ -159,6 +134,7 @@ abstract class AWorkflowController extends OCSController { * @throws OCSForbiddenException * @throws OCSException */ + #[PasswordConfirmationRequired] public function destroy(int $id): DataResponse { try { $deleted = $this->manager->deleteOperation($id, $this->getScopeContext()); diff --git a/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php index 8778f85365f..001c673df35 100644 --- a/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php +++ b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Controller; diff --git a/apps/workflowengine/lib/Controller/RequestTime.php b/apps/workflowengine/lib/Controller/RequestTime.php deleted file mode 100644 index a1d9ff4a630..00000000000 --- a/apps/workflowengine/lib/Controller/RequestTime.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.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\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\JSONResponse; - -class RequestTime extends Controller { - - /** - * @NoAdminRequired - * - * @param string $search - * @return JSONResponse - */ - public function getTimezones($search = '') { - $timezones = \DateTimeZone::listIdentifiers(); - - if ($search !== '') { - $timezones = array_filter($timezones, function ($timezone) use ($search) { - return stripos($timezone, $search) !== false; - }); - } - - $timezones = array_slice($timezones, 0, 10); - - $response = []; - foreach ($timezones as $timezone) { - $response[$timezone] = $timezone; - } - return new JSONResponse($response); - } -} diff --git a/apps/workflowengine/lib/Controller/RequestTimeController.php b/apps/workflowengine/lib/Controller/RequestTimeController.php new file mode 100644 index 00000000000..4b34f16ce0a --- /dev/null +++ b/apps/workflowengine/lib/Controller/RequestTimeController.php @@ -0,0 +1,37 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\WorkflowEngine\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\JSONResponse; + +class RequestTimeController extends Controller { + + /** + * @param string $search + * @return JSONResponse + */ + #[NoAdminRequired] + public function getTimezones($search = '') { + $timezones = \DateTimeZone::listIdentifiers(); + + if ($search !== '') { + $timezones = array_filter($timezones, function ($timezone) use ($search) { + return stripos($timezone, $search) !== false; + }); + } + + $timezones = array_slice($timezones, 0, 10); + + $response = []; + foreach ($timezones as $timezone) { + $response[$timezone] = $timezone; + } + return new JSONResponse($response); + } +} diff --git a/apps/workflowengine/lib/Controller/UserWorkflowsController.php b/apps/workflowengine/lib/Controller/UserWorkflowsController.php index dd2457dd9e8..953ce149233 100644 --- a/apps/workflowengine/lib/Controller/UserWorkflowsController.php +++ b/apps/workflowengine/lib/Controller/UserWorkflowsController.php @@ -3,32 +3,15 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Controller; use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Manager; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSForbiddenException; @@ -39,9 +22,6 @@ use Psr\Log\LoggerInterface; class UserWorkflowsController extends AWorkflowController { - /** @var IUserSession */ - private $session; - /** @var ScopeContext */ private $scopeContext; @@ -49,12 +29,10 @@ class UserWorkflowsController extends AWorkflowController { $appName, IRequest $request, Manager $manager, - IUserSession $session, - LoggerInterface $logger + private IUserSession $session, + LoggerInterface $logger, ) { parent::__construct($appName, $request, $manager, $logger); - - $this->session = $session; } /** @@ -62,45 +40,47 @@ class UserWorkflowsController extends AWorkflowController { * * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user?format=json" * - * @NoAdminRequired * @throws OCSForbiddenException */ + #[NoAdminRequired] public function index(): DataResponse { return parent::index(); } /** - * @NoAdminRequired - * * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user/OCA\\Workflow_DocToPdf\\Operation?format=json" * @throws OCSForbiddenException */ + #[NoAdminRequired] public function show(string $id): DataResponse { return parent::show($id); } /** - * @NoAdminRequired * @throws OCSBadRequestException * @throws OCSForbiddenException */ + #[NoAdminRequired] + #[PasswordConfirmationRequired] public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse { return parent::create($class, $name, $checks, $operation, $entity, $events); } /** - * @NoAdminRequired * @throws OCSBadRequestException * @throws OCSForbiddenException */ + #[NoAdminRequired] + #[PasswordConfirmationRequired] public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse { return parent::update($id, $name, $checks, $operation, $entity, $events); } /** - * @NoAdminRequired * @throws OCSForbiddenException */ + #[NoAdminRequired] + #[PasswordConfirmationRequired] public function destroy(int $id): DataResponse { return parent::destroy($id); } diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php index 3f09fcd24a1..64d552e1737 100644 --- a/apps/workflowengine/lib/Entity/File.php +++ b/apps/workflowengine/lib/Entity/File.php @@ -3,42 +3,24 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Entity; +use OC\Files\Config\UserMountCache; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\GenericEvent; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IL10N; -use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; -use OCP\Share\IManager as ShareManager; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\MapperEvent; @@ -52,50 +34,28 @@ use OCP\WorkflowEngine\IRuleMatcher; class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation { private const EVENT_NAMESPACE = '\OCP\Files::'; - - /** @var IL10N */ - protected $l10n; - /** @var IURLGenerator */ - protected $urlGenerator; - /** @var IRootFolder */ - protected $root; - /** @var ILogger */ - protected $logger; /** @var string */ protected $eventName; /** @var Event */ protected $event; - /** @var ShareManager */ - private $shareManager; - /** @var IUserSession */ - private $userSession; - /** @var ISystemTagManager */ - private $tagManager; /** @var ?Node */ private $node; /** @var ?IUser */ private $actingUser = null; - /** @var IUserManager */ - private $userManager; + /** @var UserMountCache */ + private $userMountCache; public function __construct( - IL10N $l10n, - IURLGenerator $urlGenerator, - IRootFolder $root, - ILogger $logger, - ShareManager $shareManager, - IUserSession $userSession, - ISystemTagManager $tagManager, - IUserManager $userManager + protected IL10N $l10n, + protected IURLGenerator $urlGenerator, + protected IRootFolder $root, + private IUserSession $userSession, + private ISystemTagManager $tagManager, + private IUserManager $userManager, + UserMountCache $userMountCache, + private IMountManager $mountManager, ) { - $this->l10n = $l10n; - $this->urlGenerator = $urlGenerator; - $this->root = $root; - $this->logger = $logger; - $this->shareManager = $shareManager; - $this->userSession = $userSession; - $this->tagManager = $tagManager; - $this->userManager = $userManager; + $this->userMountCache = $userMountCache; } public function getName(): string { @@ -134,14 +94,28 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation { } } - public function isLegitimatedForUserId(string $uid): bool { + public function isLegitimatedForUserId(string $userId): bool { try { $node = $this->getNode(); - if ($node->getOwner()->getUID() === $uid) { + if ($node->getOwner()?->getUID() === $userId) { return true; } - $acl = $this->shareManager->getAccessList($node, true, true); - return isset($acl['users']) && array_key_exists($uid, $acl['users']); + + if ($this->eventName === self::EVENT_NAMESPACE . 'postDelete') { + // At postDelete, the file no longer exists. Check for parent folder instead. + $fileId = $node->getParentId(); + } else { + $fileId = $node->getId(); + } + + $mountInfos = $this->userMountCache->getMountsForFileId($fileId, $userId); + foreach ($mountInfos as $mountInfo) { + $mount = $this->mountManager->getMountFromMountInfo($mountInfo); + if ($mount && $mount->getStorage() && !empty($mount->getStorage()->getCache()->get($fileId))) { + return true; + } + } + return false; } catch (NotFoundException $e) { return false; } diff --git a/apps/workflowengine/lib/Helper/LogContext.php b/apps/workflowengine/lib/Helper/LogContext.php index 2ad619f1686..9d740680bb6 100644 --- a/apps/workflowengine/lib/Helper/LogContext.php +++ b/apps/workflowengine/lib/Helper/LogContext.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Helper; diff --git a/apps/workflowengine/lib/Helper/ScopeContext.php b/apps/workflowengine/lib/Helper/ScopeContext.php index 1927aac6b40..05379f5ff43 100644 --- a/apps/workflowengine/lib/Helper/ScopeContext.php +++ b/apps/workflowengine/lib/Helper/ScopeContext.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Helper; @@ -36,7 +18,7 @@ class ScopeContext { /** @var string */ private $hash; - public function __construct(int $scope, string $scopeId = null) { + public function __construct(int $scope, ?string $scopeId = null) { $this->scope = $this->evaluateScope($scope); $this->scopeId = $this->evaluateScopeId($scopeId); } @@ -48,7 +30,7 @@ class ScopeContext { throw new \InvalidArgumentException('Invalid scope'); } - private function evaluateScopeId(string $scopeId = null): string { + private function evaluateScopeId(?string $scopeId = null): string { if ($this->scope === IManager::SCOPE_USER && trim((string)$scopeId) === '') { throw new \InvalidArgumentException('user scope requires a user id'); diff --git a/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php b/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php index a3806799ff0..e5a03fdcb2e 100644 --- a/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php +++ b/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php @@ -3,44 +3,21 @@ declare(strict_types=1); /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author François Freitag <mail@franek.fr> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\WorkflowEngine\Listener; use OCA\WorkflowEngine\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\Template; -use function class_exists; -use function function_exists; use OCP\Util; +use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent; +/** @template-implements IEventListener<LoadSettingsScriptsEvent> */ class LoadAdditionalSettingsScriptsListener implements IEventListener { public function handle(Event $event): void { - if (!function_exists('style')) { - // This is hacky, but we need to load the template class - class_exists(Template::class, true); - } - Util::addScript('core', 'files_fileinfo'); Util::addScript('core', 'files_client'); Util::addScript('core', 'systemtags'); diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 659fd2421c1..0f41679789d 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -1,36 +1,12 @@ <?php + /** - * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author blizzz <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine; use Doctrine\DBAL\Exception; -use OCP\Cache\CappedMemoryCache; use OCA\WorkflowEngine\AppInfo\Application; use OCA\WorkflowEngine\Check\FileMimeType; use OCA\WorkflowEngine\Check\FileName; @@ -46,13 +22,13 @@ use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Service\Logger; use OCA\WorkflowEngine\Service\RuleMatcher; use OCP\AppFramework\QueryException; +use OCP\Cache\CappedMemoryCache; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Storage\IStorage; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; -use OCP\ILogger; use OCP\IServerContainer; use OCP\IUserSession; use OCP\WorkflowEngine\Events\RegisterChecksEvent; @@ -65,38 +41,15 @@ use OCP\WorkflowEngine\IEntityEvent; use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IOperation; use OCP\WorkflowEngine\IRuleMatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface as LegacyDispatcher; -use Symfony\Component\EventDispatcher\GenericEvent; +use Psr\Log\LoggerInterface; class Manager implements IManager { - - /** @var IStorage */ - protected $storage; - - /** @var string */ - protected $path; - - /** @var object */ - protected $entity; - /** @var array[] */ protected $operations = []; /** @var array[] */ protected $checks = []; - /** @var IDBConnection */ - protected $connection; - - /** @var IServerContainer|\OC\Server */ - protected $container; - - /** @var IL10N */ - protected $l; - - /** @var LegacyDispatcher */ - protected $legacyEventDispatcher; - /** @var IEntity[] */ protected $registeredEntities = []; @@ -106,40 +59,20 @@ class Manager implements IManager { /** @var ICheck[] */ protected $registeredChecks = []; - /** @var ILogger */ - protected $logger; - /** @var CappedMemoryCache<int[]> */ protected CappedMemoryCache $operationsByScope; - /** @var IUserSession */ - protected $session; - - /** @var IEventDispatcher */ - private $dispatcher; - - /** @var IConfig */ - private $config; - public function __construct( - IDBConnection $connection, - IServerContainer $container, - IL10N $l, - LegacyDispatcher $eventDispatcher, - ILogger $logger, - IUserSession $session, - IEventDispatcher $dispatcher, - IConfig $config + protected IDBConnection $connection, + protected IServerContainer $container, + protected IL10N $l, + protected LoggerInterface $logger, + protected IUserSession $session, + private IEventDispatcher $dispatcher, + private IConfig $config, + private ICacheFactory $cacheFactory, ) { - $this->connection = $connection; - $this->container = $container; - $this->l = $l; - $this->legacyEventDispatcher = $eventDispatcher; - $this->logger = $logger; $this->operationsByScope = new CappedMemoryCache(64); - $this->session = $session; - $this->dispatcher = $dispatcher; - $this->config = $config; } public function getRuleMatcher(): IRuleMatcher { @@ -153,6 +86,12 @@ class Manager implements IManager { } public function getAllConfiguredEvents() { + $cache = $this->cacheFactory->createDistributed('flow'); + $cached = $cache->get('events'); + if ($cached !== null) { + return $cached; + } + $query = $this->connection->getQueryBuilder(); $query->select('class', 'entity') @@ -161,7 +100,7 @@ class Manager implements IManager { ->where($query->expr()->neq('events', $query->createNamedParameter('[]'), IQueryBuilder::PARAM_STR)) ->groupBy('class', 'entity', $query->expr()->castColumn('events', IQueryBuilder::PARAM_STR)); - $result = $query->execute(); + $result = $query->executeQuery(); $operations = []; while ($row = $result->fetch()) { $eventNames = \json_decode($row['events']); @@ -176,6 +115,8 @@ class Manager implements IManager { } $result->closeCursor(); + $cache->set('events', $operations, 3600); + return $operations; } @@ -189,6 +130,13 @@ class Manager implements IManager { return $scopesByOperation[$operationClass]; } + try { + /** @var IOperation $operation */ + $operation = $this->container->query($operationClass); + } catch (QueryException $e) { + return []; + } + $query = $this->connection->getQueryBuilder(); $query->selectDistinct('s.type') @@ -198,11 +146,16 @@ class Manager implements IManager { ->where($query->expr()->eq('o.class', $query->createParameter('operationClass'))); $query->setParameters(['operationClass' => $operationClass]); - $result = $query->execute(); + $result = $query->executeQuery(); $scopesByOperation[$operationClass] = []; while ($row = $result->fetch()) { $scope = new ScopeContext($row['type'], $row['value']); + + if (!$operation->isAvailableForScope((int)$row['type'])) { + continue; + } + $scopesByOperation[$operationClass][$scope->getHash()] = $scope; } @@ -228,10 +181,21 @@ class Manager implements IManager { } $query->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]); - $result = $query->execute(); + $result = $query->executeQuery(); $this->operations[$scopeContext->getHash()] = []; while ($row = $result->fetch()) { + try { + /** @var IOperation $operation */ + $operation = $this->container->query($row['class']); + } catch (QueryException $e) { + continue; + } + + if (!$operation->isAvailableForScope((int)$row['scope_type'])) { + continue; + } + if (!isset($this->operations[$scopeContext->getHash()][$row['class']])) { $this->operations[$scopeContext->getHash()][$row['class']] = []; } @@ -258,7 +222,7 @@ class Manager implements IManager { $query->select('*') ->from('flow_operations') ->where($query->expr()->eq('id', $query->createNamedParameter($id))); - $result = $query->execute(); + $result = $query->executeQuery(); $row = $result->fetch(); $result->closeCursor(); @@ -275,7 +239,7 @@ class Manager implements IManager { array $checkIds, string $operation, string $entity, - array $events + array $events, ): int { $query = $this->connection->getQueryBuilder(); $query->insert('flow_operations') @@ -287,7 +251,9 @@ class Manager implements IManager { 'entity' => $query->createNamedParameter($entity), 'events' => $query->createNamedParameter(json_encode($events)) ]); - $query->execute(); + $query->executeStatement(); + + $this->cacheFactory->createDistributed('flow')->remove('events'); return $query->getLastInsertId(); } @@ -299,7 +265,7 @@ class Manager implements IManager { * @param string $operation * @return array The added operation * @throws \UnexpectedValueException - * @throw Exception + * @throws Exception */ public function addOperation( string $class, @@ -308,9 +274,9 @@ class Manager implements IManager { string $operation, ScopeContext $scope, string $entity, - array $events + array $events, ) { - $this->validateOperation($class, $name, $checks, $operation, $entity, $events); + $this->validateOperation($class, $name, $checks, $operation, $scope, $entity, $events); $this->connection->beginTransaction(); @@ -344,11 +310,11 @@ class Manager implements IManager { ->where($qb->expr()->eq('s.type', $qb->createParameter('scope'))); if ($scopeContext->getScope() !== IManager::SCOPE_ADMIN) { - $qb->where($qb->expr()->eq('s.value', $qb->createParameter('scopeId'))); + $qb->andWhere($qb->expr()->eq('s.value', $qb->createParameter('scopeId'))); } $qb->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]); - $result = $qb->execute(); + $result = $qb->executeQuery(); $operations = []; while (($opId = $result->fetchOne()) !== false) { @@ -377,13 +343,13 @@ class Manager implements IManager { string $operation, ScopeContext $scopeContext, string $entity, - array $events + array $events, ): array { if (!$this->canModify($id, $scopeContext)) { throw new \DomainException('Target operation not within scope'); }; $row = $this->getOperation($id); - $this->validateOperation($row['class'], $name, $checks, $operation, $entity, $events); + $this->validateOperation($row['class'], $name, $checks, $operation, $scopeContext, $entity, $events); $checkIds = []; try { @@ -407,6 +373,7 @@ class Manager implements IManager { throw $e; } unset($this->operations[$scopeContext->getHash()]); + $this->cacheFactory->createDistributed('flow')->remove('events'); return $this->getOperation($id); } @@ -427,12 +394,12 @@ class Manager implements IManager { $this->connection->beginTransaction(); $result = (bool)$query->delete('flow_operations') ->where($query->expr()->eq('id', $query->createNamedParameter($id))) - ->execute(); + ->executeStatement(); if ($result) { $qb = $this->connection->getQueryBuilder(); $result &= (bool)$qb->delete('flow_operations_scope') ->where($qb->expr()->eq('operation_id', $qb->createNamedParameter($id))) - ->execute(); + ->executeStatement(); } $this->connection->commit(); } catch (Exception $e) { @@ -444,6 +411,8 @@ class Manager implements IManager { unset($this->operations[$scopeContext->getHash()]); } + $this->cacheFactory->createDistributed('flow')->remove('events'); + return $result; } @@ -483,9 +452,12 @@ class Manager implements IManager { * @param string $name * @param array[] $checks * @param string $operation + * @param ScopeContext $scope + * @param string $entity + * @param array $events * @throws \UnexpectedValueException */ - public function validateOperation($class, $name, array $checks, $operation, string $entity, array $events) { + public function validateOperation($class, $name, array $checks, $operation, ScopeContext $scope, string $entity, array $events) { try { /** @var IOperation $instance */ $instance = $this->container->query($class); @@ -497,6 +469,10 @@ class Manager implements IManager { throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class])); } + if (!$instance->isAvailableForScope($scope->getScope())) { + throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class])); + } + $this->validateEvents($entity, $events, $instance); if (count($checks) === 0) { @@ -562,11 +538,11 @@ class Manager implements IManager { $query->select('*') ->from('flow_checks') ->where($query->expr()->in('id', $query->createNamedParameter($checkIds, IQueryBuilder::PARAM_INT_ARRAY))); - $result = $query->execute(); + $result = $query->executeQuery(); while ($row = $result->fetch()) { - $this->checks[(int) $row['id']] = $row; - $checks[(int) $row['id']] = $row; + $this->checks[(int)$row['id']] = $row; + $checks[(int)$row['id']] = $row; } $result->closeCursor(); @@ -593,11 +569,11 @@ class Manager implements IManager { $query->select('id') ->from('flow_checks') ->where($query->expr()->eq('hash', $query->createNamedParameter($hash))); - $result = $query->execute(); + $result = $query->executeQuery(); if ($row = $result->fetch()) { $result->closeCursor(); - return (int) $row['id']; + return (int)$row['id']; } $query = $this->connection->getQueryBuilder(); @@ -608,7 +584,7 @@ class Manager implements IManager { 'value' => $query->createNamedParameter($value), 'hash' => $query->createNamedParameter($hash), ]); - $query->execute(); + $query->executeStatement(); return $query->getLastInsertId(); } @@ -622,7 +598,7 @@ class Manager implements IManager { 'type' => $query->createNamedParameter($scope->getScope()), 'value' => $query->createNamedParameter($scope->getScopeId()), ]); - $insertQuery->execute(); + $insertQuery->executeStatement(); } public function formatOperation(array $operation): array { @@ -648,7 +624,6 @@ class Manager implements IManager { */ public function getEntitiesList(): array { $this->dispatcher->dispatchTyped(new RegisterEntitiesEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this)); return array_values(array_merge($this->getBuildInEntities(), $this->registeredEntities)); } @@ -658,7 +633,6 @@ class Manager implements IManager { */ public function getOperatorList(): array { $this->dispatcher->dispatchTyped(new RegisterOperationsEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this)); return array_merge($this->getBuildInOperators(), $this->registeredOperators); } @@ -668,7 +642,6 @@ class Manager implements IManager { */ public function getCheckList(): array { $this->dispatcher->dispatchTyped(new RegisterChecksEvent($this)); - $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this)); return array_merge($this->getBuildInChecks(), $this->registeredChecks); } @@ -694,7 +667,7 @@ class Manager implements IManager { File::class => $this->container->query(File::class), ]; } catch (QueryException $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return []; } } @@ -708,7 +681,7 @@ class Manager implements IManager { // None yet ]; } catch (QueryException $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return []; } } @@ -730,7 +703,7 @@ class Manager implements IManager { $this->container->query(UserGroupMembership::class), ]; } catch (QueryException $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return []; } } diff --git a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php index 974793e99b2..633d946cd7e 100644 --- a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php +++ b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Migration; @@ -34,11 +16,9 @@ use OCP\WorkflowEngine\IManager; class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { - /** @var IDBConnection */ - private $dbc; - - public function __construct(IDBConnection $dbc) { - $this->dbc = $dbc; + public function __construct( + private IDBConnection $dbc, + ) { } public function getName() { @@ -59,7 +39,7 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { $insertQuery = $qb->insert('flow_operations_scope'); while (($id = $ids->fetchOne()) !== false) { $insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]); - $insertQuery->execute(); + $insertQuery->executeStatement(); } } @@ -73,7 +53,7 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { // in case the repair step is executed multiple times for whatever reason. /** @var IResult $result */ - $result = $selectQuery->execute(); + $result = $selectQuery->executeQuery(); return $result; } } diff --git a/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php b/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php index 351c1aa3fa5..93f423cada7 100644 --- a/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php +++ b/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php @@ -3,37 +3,16 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Migration; use Closure; use Doctrine\DBAL\Schema\Table; -use OCP\DB\Types; use OCA\WorkflowEngine\Entity\File; use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; diff --git a/apps/workflowengine/lib/Migration/Version2200Date20210805101925.php b/apps/workflowengine/lib/Migration/Version2200Date20210805101925.php index 9f2049dc611..841277acfce 100644 --- a/apps/workflowengine/lib/Migration/Version2200Date20210805101925.php +++ b/apps/workflowengine/lib/Migration/Version2200Date20210805101925.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2021 Vincent Petry <vincent@nextcloud.com> - * - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Migration; diff --git a/apps/workflowengine/lib/Service/Logger.php b/apps/workflowengine/lib/Service/Logger.php index 6ad7f8c4847..494240bc403 100644 --- a/apps/workflowengine/lib/Service/Logger.php +++ b/apps/workflowengine/lib/Service/Logger.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Service; @@ -36,24 +17,17 @@ use OCP\Log\ILogFactory; use Psr\Log\LoggerInterface; class Logger { - /** @var ILogger */ - protected $generalLogger; - /** @var LoggerInterface */ - protected $flowLogger; - /** @var IConfig */ - private $config; - /** @var ILogFactory */ - private $logFactory; - - public function __construct(ILogger $generalLogger, IConfig $config, ILogFactory $logFactory) { - $this->generalLogger = $generalLogger; - $this->config = $config; - $this->logFactory = $logFactory; + protected ?LoggerInterface $flowLogger = null; + public function __construct( + protected LoggerInterface $generalLogger, + private IConfig $config, + private ILogFactory $logFactory, + ) { $this->initLogger(); } - protected function initLogger() { + protected function initLogger(): void { $default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log'; $logFile = trim((string)$this->config->getAppValue(Application::APP_ID, 'logfile', $default)); if ($logFile !== '') { @@ -154,7 +128,7 @@ class Logger { protected function log( string $message, array $context, - LogContext $logContext + LogContext $logContext, ): void { if (!isset($context['app'])) { $context['app'] = Application::APP_ID; diff --git a/apps/workflowengine/lib/Service/RuleMatcher.php b/apps/workflowengine/lib/Service/RuleMatcher.php index 13cba8a6aa5..c95387e14ee 100644 --- a/apps/workflowengine/lib/Service/RuleMatcher.php +++ b/apps/workflowengine/lib/Service/RuleMatcher.php @@ -3,29 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Calviño Sánchez <danxuliu@gmail.com> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Service; @@ -48,39 +27,24 @@ use RuntimeException; class RuleMatcher implements IRuleMatcher { - /** @var IUserSession */ - protected $session; - /** @var IManager */ - protected $manager; /** @var array */ protected $contexts; - /** @var IServerContainer */ - protected $container; /** @var array */ protected $fileInfo = []; - /** @var IL10N */ - protected $l; /** @var IOperation */ protected $operation; /** @var IEntity */ protected $entity; - /** @var Logger */ - protected $logger; /** @var string */ protected $eventName; public function __construct( - IUserSession $session, - IServerContainer $container, - IL10N $l, - Manager $manager, - Logger $logger + protected IUserSession $session, + protected IServerContainer $container, + protected IL10N $l, + protected Manager $manager, + protected Logger $logger, ) { - $this->session = $session; - $this->manager = $manager; - $this->container = $container; - $this->l = $l; - $this->logger = $logger; } public function setFileInfo(IStorage $storage, string $path, bool $isDir = false): void { diff --git a/apps/workflowengine/lib/Settings/ASettings.php b/apps/workflowengine/lib/Settings/ASettings.php index f3cb8d76bba..23e958755de 100644 --- a/apps/workflowengine/lib/Settings/ASettings.php +++ b/apps/workflowengine/lib/Settings/ASettings.php @@ -3,30 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Settings; @@ -48,30 +26,15 @@ use OCP\WorkflowEngine\IOperation; use OCP\WorkflowEngine\ISpecificOperation; abstract class ASettings implements ISettings { - private IL10N $l10n; - private string $appName; - private IEventDispatcher $eventDispatcher; - protected Manager $manager; - private IInitialState $initialStateService; - private IConfig $config; - private IURLGenerator $urlGenerator; - public function __construct( - string $appName, - IL10N $l, - IEventDispatcher $eventDispatcher, - Manager $manager, - IInitialState $initialStateService, - IConfig $config, - IURLGenerator $urlGenerator + private string $appName, + private IL10N $l10n, + private IEventDispatcher $eventDispatcher, + protected Manager $manager, + private IInitialState $initialStateService, + private IConfig $config, + private IURLGenerator $urlGenerator, ) { - $this->appName = $appName; - $this->l10n = $l; - $this->eventDispatcher = $eventDispatcher; - $this->manager = $manager; - $this->initialStateService = $initialStateService; - $this->config = $config; - $this->urlGenerator = $urlGenerator; } abstract public function getScope(): int; @@ -132,8 +95,8 @@ abstract class ASettings implements ISettings { /** * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. * * E.g.: 70 */ diff --git a/apps/workflowengine/lib/Settings/Admin.php b/apps/workflowengine/lib/Settings/Admin.php index 25915ba08a4..c2018593c66 100644 --- a/apps/workflowengine/lib/Settings/Admin.php +++ b/apps/workflowengine/lib/Settings/Admin.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Settings; diff --git a/apps/workflowengine/lib/Settings/Personal.php b/apps/workflowengine/lib/Settings/Personal.php index 8b575e00219..0a70f8dbe75 100644 --- a/apps/workflowengine/lib/Settings/Personal.php +++ b/apps/workflowengine/lib/Settings/Personal.php @@ -3,29 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Härtl <jus@bitgrid.net> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Settings; diff --git a/apps/workflowengine/lib/Settings/Section.php b/apps/workflowengine/lib/Settings/Section.php index c3fee45f5df..aa790c9ddcc 100644 --- a/apps/workflowengine/lib/Settings/Section.php +++ b/apps/workflowengine/lib/Settings/Section.php @@ -1,27 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WorkflowEngine\Settings; @@ -31,18 +12,14 @@ use OCP\IURLGenerator; use OCP\Settings\IIconSection; class Section implements IIconSection { - /** @var IL10N */ - private $l; - /** @var IURLGenerator */ - private $url; - /** * @param IURLGenerator $url * @param IL10N $l */ - public function __construct(IURLGenerator $url, IL10N $l) { - $this->url = $url; - $this->l = $l; + public function __construct( + private IURLGenerator $url, + private IL10N $l, + ) { } /** |