aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib
diff options
context:
space:
mode:
authorRobin Windey <ro.windey@gmail.com>2025-01-18 17:38:39 +0000
committerRobin Windey <ro.windey@gmail.com>2025-01-18 17:38:39 +0000
commit4654ddbaca0a35e0ba7637b148f9888ed252019e (patch)
treeb175482aaf49425e0043f14c5dbea0fdd5cd0716 /apps/workflowengine/lib
parent0d3edd28b17acb59c1ea512cad5db5ea85444813 (diff)
downloadnextcloud-server-feat/add-directory-check-workflowengine.tar.gz
nextcloud-server-feat/add-directory-check-workflowengine.zip
* Partially implements #27591 Signed-off-by: Robin Windey <ro.windey@gmail.com>
Diffstat (limited to 'apps/workflowengine/lib')
-rw-r--r--apps/workflowengine/lib/Check/Directory.php58
-rw-r--r--apps/workflowengine/lib/Manager.php2
2 files changed, 60 insertions, 0 deletions
diff --git a/apps/workflowengine/lib/Check/Directory.php b/apps/workflowengine/lib/Check/Directory.php
new file mode 100644
index 00000000000..4acdf00672e
--- /dev/null
+++ b/apps/workflowengine/lib/Check/Directory.php
@@ -0,0 +1,58 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\WorkflowEngine\Check;
+
+use OCA\WorkflowEngine\Entity\File;
+use OCP\IL10N;
+use OCP\WorkflowEngine\IFileCheck;
+
+class Directory extends AbstractStringCheck implements IFileCheck {
+ use TFileCheck;
+
+ /**
+ * @param IL10N $l
+ */
+ public function __construct(
+ IL10N $l,
+ ) {
+ parent::__construct($l);
+ }
+
+ /**
+ * @return string
+ */
+ protected function getActualValue(): string {
+ if ($this->path === null) {
+ return '';
+ }
+ // files/some/path -> some/path
+ return preg_replace('/^files\//', '', pathinfo($this->path, PATHINFO_DIRNAME));
+ }
+
+ /**
+ * @param string $operator
+ * @param string $checkValue
+ * @param string $actualValue
+ * @return bool
+ */
+ protected function executeStringCheck($operator, $checkValue, $actualValue) {
+ if ($operator === 'is' || $operator === '!is') {
+ $checkValue = ltrim(rtrim($checkValue, '/'), '/');
+ }
+ return parent::executeStringCheck($operator, $checkValue, $actualValue);
+ }
+
+ public function supportedEntities(): array {
+ return [ File::class ];
+ }
+
+ public function isAvailableForScope(int $scope): bool {
+ return true;
+ }
+}
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 7d14fc83449..dc075970c25 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -7,6 +7,7 @@ namespace OCA\WorkflowEngine;
use Doctrine\DBAL\Exception;
use OCA\WorkflowEngine\AppInfo\Application;
+use OCA\WorkflowEngine\Check\Directory;
use OCA\WorkflowEngine\Check\FileMimeType;
use OCA\WorkflowEngine\Check\FileName;
use OCA\WorkflowEngine\Check\FileSize;
@@ -691,6 +692,7 @@ class Manager implements IManager {
protected function getBuildInChecks(): array {
try {
return [
+ $this->container->query(Directory::class),
$this->container->query(FileMimeType::class),
$this->container->query(FileName::class),
$this->container->query(FileSize::class),