Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enables the file name check also to match name of mountpoints #24703

Merged
merged 2 commits into from
Dec 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions apps/workflowengine/lib/Check/FileName.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

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;
Expand All @@ -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;
}

/**
Expand Down