From c0c88e3bd84e0434e2cf704f973109ef7b67df02 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 15 Dec 2020 00:02:43 +0100 Subject: [PATCH 1/2] enables the file name check also to match name of mountpoints Signed-off-by: Arthur Schiwon --- apps/workflowengine/lib/Check/FileName.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php index 9f2a78aef6..893a9a7260 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\WorkflowEngine\Check; use OCA\WorkflowEngine\Entity\File; +use OCP\Files\Mount\IMountManager; use OCP\IL10N; use OCP\IRequest; use OCP\WorkflowEngine\IFileCheck; @@ -33,21 +34,38 @@ class FileName extends AbstractStringCheck implements IFileCheck { /** @var IRequest */ protected $request; + /** @var IMountManager */ + private $mountManager; /** * @param IL10N $l * @param IRequest $request */ - public function __construct(IL10N $l, IRequest $request) { + public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) { parent::__construct($l); $this->request = $request; + $this->mountManager = $mountManager; } /** * @return string */ protected function getActualValue(): string { - return $this->path === null ? '' : basename($this->path); + $fileName = $this->path === null ? '' : basename($this->path); + if ($fileName === '' && !$this->storage->isLocal()) { + // Return the mountpoint name of external storages that are not mounted as user home + $mountPoints = $this->mountManager->findByStorageId($this->storage->getId()); + if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') { + return $fileName; + } + $mountPointPath = rtrim($mountPoints[0]->getMountPoint(), '/'); + $mountPointPieces = explode('/', $mountPointPath); + $mountPointName = array_pop($mountPointPieces); + if (!empty($mountPointName) && $mountPointName !== 'files' && count($mountPointPieces) !== 2) { + return $mountPointName; + } + } + return $fileName; } /** From b432a9f5da6dd6286aabfba154e5dbabb89c516e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 15 Dec 2020 11:50:04 +0100 Subject: [PATCH 2/2] consider local external storages, too Signed-off-by: Arthur Schiwon --- apps/workflowengine/lib/Check/FileName.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php index 893a9a7260..9a564f85f6 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\WorkflowEngine\Check; +use OC\Files\Storage\Local; use OCA\WorkflowEngine\Entity\File; use OCP\Files\Mount\IMountManager; use OCP\IL10N; @@ -52,7 +53,7 @@ class FileName extends AbstractStringCheck implements IFileCheck { */ protected function getActualValue(): string { $fileName = $this->path === null ? '' : basename($this->path); - if ($fileName === '' && !$this->storage->isLocal()) { + if ($fileName === '' && (!$this->storage->isLocal() || $this->storage->instanceOfStorage(Local::class))) { // Return the mountpoint name of external storages that are not mounted as user home $mountPoints = $this->mountManager->findByStorageId($this->storage->getId()); if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') {