diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-08-21 17:36:01 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2020-08-25 08:44:19 +0000 |
commit | ace667bce791c42adffb160f2443e1a50938a7fe (patch) | |
tree | a020274104f22c41bbc148e5df1ec5cfc09bd749 | |
parent | 02264a11a8aa6c5ab6eca596ef905438cdf38227 (diff) | |
download | nextcloud-server-ace667bce791c42adffb160f2443e1a50938a7fe.tar.gz nextcloud-server-ace667bce791c42adffb160f2443e1a50938a7fe.zip |
fix possible leaking scope in Flow
- a configured flow can be brought into consideration, despite its event
was not fired
- it could either run through
- or run into a RuntimeException and killing processing of valid flows
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r-- | apps/workflowengine/lib/AppInfo/Application.php | 1 | ||||
-rw-r--r-- | apps/workflowengine/lib/Service/RuleMatcher.php | 14 | ||||
-rw-r--r-- | lib/public/WorkflowEngine/IRuleMatcher.php | 10 |
3 files changed, 25 insertions, 0 deletions
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index 289ac167ac5..0fb4d7063bd 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -96,6 +96,7 @@ class Application extends \OCP\AppFramework\App { /** @var IOperation $operation */ $operation = $this->getContainer()->query($operationClass); + $ruleMatcher->setEventName($eventName); $ruleMatcher->setEntity($entity); $ruleMatcher->setOperation($operation); diff --git a/apps/workflowengine/lib/Service/RuleMatcher.php b/apps/workflowengine/lib/Service/RuleMatcher.php index fefb77d4fb1..11000b643bd 100644 --- a/apps/workflowengine/lib/Service/RuleMatcher.php +++ b/apps/workflowengine/lib/Service/RuleMatcher.php @@ -61,6 +61,8 @@ class RuleMatcher implements IRuleMatcher { protected $entity; /** @var Logger */ protected $logger; + /** @var string */ + protected $eventName; public function __construct( IUserSession $session, @@ -100,6 +102,13 @@ class RuleMatcher implements IRuleMatcher { $this->entity = $entity; } + public function setEventName(string $eventName): void { + if ($this->eventName !== null) { + throw new RuntimeException('This method must not be called more than once'); + } + $this->eventName = $eventName; + } + public function getEntity(): IEntity { if($this->entity === null) { throw new \LogicException('Entity was not set yet'); @@ -154,6 +163,11 @@ class RuleMatcher implements IRuleMatcher { $matches = []; foreach ($operations as $operation) { + $configuredEvents = json_decode($operation['events'], true); + if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) { + continue; + } + $checkIds = json_decode($operation['checks'], true); $checks = $this->manager->getChecks($checkIds); diff --git a/lib/public/WorkflowEngine/IRuleMatcher.php b/lib/public/WorkflowEngine/IRuleMatcher.php index cb52001a1a2..47ab3a25c3a 100644 --- a/lib/public/WorkflowEngine/IRuleMatcher.php +++ b/lib/public/WorkflowEngine/IRuleMatcher.php @@ -78,4 +78,14 @@ interface IRuleMatcher extends IFileCheck { * @since 18.0.0 */ public function getEntity(): IEntity; + + /** + * this method can be called once to set the event name that is currently + * being processed. The workflow engine takes care of this usually, only an + * IComplexOperation might want to make use of it. + * + * @throws RuntimeException + * @since 20.0.0 + */ + public function setEventName(string $eventName): void; } |