]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix possible leaking scope in Flow 22359/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 21 Aug 2020 15:36:01 +0000 (17:36 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 24 Aug 2020 11:44:01 +0000 (13:44 +0200)
- 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>
apps/workflowengine/lib/AppInfo/Application.php
apps/workflowengine/lib/Service/RuleMatcher.php
lib/public/WorkflowEngine/IRuleMatcher.php

index 8f762f0d707cff9ca9fbad818158a256af00bcdd..3b253acbce1cde8ea83bb3716f2daa5060ab5a2a 100644 (file)
@@ -65,6 +65,7 @@ class Application extends App implements IBootstrap {
        private function registerRuleListeners(IEventDispatcher $dispatcher,
                                                                                   IServerContainer $container,
                                                                                   ILogger $logger): void {
+               /** @var Manager $manager */
                $manager = $container->query(Manager::class);
                $configuredEvents = $manager->getAllConfiguredEvents();
 
@@ -81,6 +82,7 @@ class Application extends App implements IBootstrap {
                                                                /** @var IOperation $operation */
                                                                $operation = $container->query($operationClass);
 
+                                                               $ruleMatcher->setEventName($eventName);
                                                                $ruleMatcher->setEntity($entity);
                                                                $ruleMatcher->setOperation($operation);
 
index 05ea16d68166fa39550822680f2a0d8d0e4e08d6..0ae26627427c7350a7c1b9852720f850cea96f90 100644 (file)
@@ -62,6 +62,8 @@ class RuleMatcher implements IRuleMatcher {
        protected $entity;
        /** @var Logger */
        protected $logger;
+       /** @var string */
+       protected $eventName;
 
        public function __construct(
                IUserSession $session,
@@ -101,6 +103,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');
@@ -155,6 +164,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);
 
index cb52001a1a2e3aaca2a96c4aee3df55a1bab2414..47ab3a25c3a03b5c06691017f894cf7546bf8aa8 100644 (file)
@@ -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;
 }