diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2020-12-18 11:43:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-18 11:43:40 +0100 |
commit | 7a1b45ab76f9fe013097e4e72e70d7da287bb476 (patch) | |
tree | baf39a751e2a0cb98160353dcfc583b496132ed4 /apps | |
parent | 2492b448e954c071e7d65966cc1200087b08cbc0 (diff) | |
parent | 04cd1348ec2c6ee2f4d6d728d335f5080328853d (diff) | |
download | nextcloud-server-7a1b45ab76f9fe013097e4e72e70d7da287bb476.tar.gz nextcloud-server-7a1b45ab76f9fe013097e4e72e70d7da287bb476.zip |
Merge pull request #24703 from nextcloud/fix/noid/wfe-filename-mountpoint-check
enables the file name check also to match name of mountpoints
Diffstat (limited to 'apps')
-rw-r--r-- | apps/workflowengine/lib/Check/FileName.php | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php index 9f2a78aef62..9a564f85f63 100644 --- a/apps/workflowengine/lib/Check/FileName.php +++ b/apps/workflowengine/lib/Check/FileName.php @@ -23,7 +23,9 @@ 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; use OCP\IRequest; use OCP\WorkflowEngine\IFileCheck; @@ -33,21 +35,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() || $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') { + 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; } /** |