Skip to content

Commit c9a1379

Browse files
authored
Merge pull request #22410 from nextcloud/backport/22359/stable19
[stable19] fix possible leaking scope in Flow
2 parents 7aeb222 + f8417cc commit c9a1379

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

apps/workflowengine/lib/AppInfo/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function ($event) use ($eventName, $operationClass, $entityClass) {
9595
/** @var IOperation $operation */
9696
$operation = $this->getContainer()->query($operationClass);
9797

98+
$ruleMatcher->setEventName($eventName);
9899
$ruleMatcher->setEntity($entity);
99100
$ruleMatcher->setOperation($operation);
100101

apps/workflowengine/lib/Service/RuleMatcher.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class RuleMatcher implements IRuleMatcher {
6262
protected $entity;
6363
/** @var Logger */
6464
protected $logger;
65+
/** @var string */
66+
protected $eventName;
6567

6668
public function __construct(
6769
IUserSession $session,
@@ -101,6 +103,13 @@ public function setEntity(IEntity $entity): void {
101103
$this->entity = $entity;
102104
}
103105

106+
public function setEventName(string $eventName): void {
107+
if ($this->eventName !== null) {
108+
throw new RuntimeException('This method must not be called more than once');
109+
}
110+
$this->eventName = $eventName;
111+
}
112+
104113
public function getEntity(): IEntity {
105114
if ($this->entity === null) {
106115
throw new \LogicException('Entity was not set yet');
@@ -155,6 +164,11 @@ public function getMatchingOperations(string $class, bool $returnFirstMatchingOp
155164

156165
$matches = [];
157166
foreach ($operations as $operation) {
167+
$configuredEvents = json_decode($operation['events'], true);
168+
if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) {
169+
continue;
170+
}
171+
158172
$checkIds = json_decode($operation['checks'], true);
159173
$checks = $this->manager->getChecks($checkIds);
160174

lib/public/WorkflowEngine/IRuleMatcher.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ public function setEntity(IEntity $entity): void;
7878
* @since 18.0.0
7979
*/
8080
public function getEntity(): IEntity;
81+
82+
/**
83+
* this method can be called once to set the event name that is currently
84+
* being processed. The workflow engine takes care of this usually, only an
85+
* IComplexOperation might want to make use of it.
86+
*
87+
* @throws RuntimeException
88+
* @since 19.0.3
89+
*/
90+
public function setEventName(string $eventName): void;
8191
}

0 commit comments

Comments
 (0)