aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-08-06 09:36:32 +0200
committerGitHub <noreply@github.com>2020-08-06 09:36:32 +0200
commit3f1c48598dc5aa903942d5aa90c550b7f9b4c01f (patch)
tree0d2b329264150aff216e8dc9d59087ee5bee72fc /apps
parent5b6246f52a4577d7ec1f2c5e54779282d7beb619 (diff)
parentb59efb61bd462ae1d62724abeb052fb2870836f6 (diff)
downloadnextcloud-server-3f1c48598dc5aa903942d5aa90c550b7f9b4c01f.tar.gz
nextcloud-server-3f1c48598dc5aa903942d5aa90c550b7f9b4c01f.zip
Merge pull request #22112 from nextcloud/enh/noid/flow-entity-recreatable-state
Allow Flow entity state to be recreated
Diffstat (limited to 'apps')
-rw-r--r--apps/workflowengine/lib/Entity/File.php64
-rw-r--r--apps/workflowengine/tests/ManagerTest.php4
2 files changed, 60 insertions, 8 deletions
diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php
index 4f98a3e5cad..8daeaae6426 100644
--- a/apps/workflowengine/lib/Entity/File.php
+++ b/apps/workflowengine/lib/Entity/File.php
@@ -34,18 +34,21 @@ use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IManager as ShareManager;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\MapperEvent;
+use OCP\WorkflowEngine\EntityContext\IContextPortation;
use OCP\WorkflowEngine\EntityContext\IDisplayText;
use OCP\WorkflowEngine\EntityContext\IUrl;
use OCP\WorkflowEngine\GenericEntityEvent;
use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IRuleMatcher;
-class File implements IEntity, IDisplayText, IUrl {
+class File implements IEntity, IDisplayText, IUrl, IContextPortation {
private const EVENT_NAMESPACE = '\OCP\Files::';
/** @var IL10N */
@@ -66,7 +69,12 @@ class File implements IEntity, IDisplayText, IUrl {
private $userSession;
/** @var ISystemTagManager */
private $tagManager;
-
+ /** @var ?Node */
+ private $node;
+ /** @var ?IUser */
+ private $actingUser = null;
+ /** @var IUserManager */
+ private $userManager;
public function __construct(
IL10N $l10n,
@@ -75,7 +83,8 @@ class File implements IEntity, IDisplayText, IUrl {
ILogger $logger,
ShareManager $shareManager,
IUserSession $userSession,
- ISystemTagManager $tagManager
+ ISystemTagManager $tagManager,
+ IUserManager $userManager
) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
@@ -84,6 +93,7 @@ class File implements IEntity, IDisplayText, IUrl {
$this->shareManager = $shareManager;
$this->userSession = $userSession;
$this->tagManager = $tagManager;
+ $this->userManager = $userManager;
}
public function getName(): string {
@@ -112,6 +122,7 @@ class File implements IEntity, IDisplayText, IUrl {
}
$this->eventName = $eventName;
$this->event = $event;
+ $this->actingUser = $this->actingUser ?? $this->userSession->getUser();
try {
$node = $this->getNode();
$ruleMatcher->setEntitySubject($this, $node);
@@ -138,6 +149,9 @@ class File implements IEntity, IDisplayText, IUrl {
* @throws NotFoundException
*/
protected function getNode(): Node {
+ if ($this->node) {
+ return $this->node;
+ }
if (!$this->event instanceof GenericEvent && !$this->event instanceof MapperEvent) {
throw new NotFoundException();
}
@@ -155,8 +169,9 @@ class File implements IEntity, IDisplayText, IUrl {
throw new NotFoundException();
}
$nodes = $this->root->getById((int)$this->event->getObjectId());
- if (is_array($nodes) && !empty($nodes)) {
- return array_shift($nodes);
+ if (is_array($nodes) && isset($nodes[0])) {
+ $this->node = $nodes[0];
+ return $this->node;
}
break;
}
@@ -164,7 +179,6 @@ class File implements IEntity, IDisplayText, IUrl {
}
public function getDisplayText(int $verbosity = 0): string {
- $user = $this->userSession->getUser();
try {
$node = $this->getNode();
} catch (NotFoundException $e) {
@@ -172,7 +186,7 @@ class File implements IEntity, IDisplayText, IUrl {
}
$options = [
- $user ? $user->getDisplayName() : $this->l10n->t('Someone'),
+ $this->actingUser ? $this->actingUser->getDisplayName() : $this->l10n->t('Someone'),
$node->getName()
];
@@ -220,4 +234,40 @@ class File implements IEntity, IDisplayText, IUrl {
return '';
}
}
+
+ /**
+ * @inheritDoc
+ */
+ public function exportContextIDs(): array {
+ $nodeOwner = $this->getNode()->getOwner();
+ $actingUserId = null;
+ if ($this->actingUser instanceof IUser) {
+ $actingUserId = $this->actingUser->getUID();
+ } elseif ($this->userSession->getUser() instanceof IUser) {
+ $actingUserId = $this->userSession->getUser()->getUID();
+ }
+ return [
+ 'eventName' => $this->eventName,
+ 'nodeId' => $this->getNode()->getId(),
+ 'nodeOwnerId' => $nodeOwner ? $nodeOwner->getUID() : null,
+ 'actingUserId' => $actingUserId,
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function importContextIDs(array $contextIDs): void {
+ $this->eventName = $contextIDs['eventName'];
+ if ($contextIDs['nodeOwnerId'] !== null) {
+ $userFolder = $this->root->getUserFolder($contextIDs['nodeOwnerId']);
+ $nodes = $userFolder->getById($contextIDs['nodeId']);
+ } else {
+ $nodes = $this->root->getById($contextIDs['nodeId']);
+ }
+ $this->node = $nodes[0] ?? null;
+ if ($contextIDs['actingUserId']) {
+ $this->actingUser = $this->userManager->get($contextIDs['actingUserId']);
+ }
+ }
}
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php
index 512d5dc1f61..0022fc37cb9 100644
--- a/apps/workflowengine/tests/ManagerTest.php
+++ b/apps/workflowengine/tests/ManagerTest.php
@@ -33,6 +33,7 @@ use OCP\IL10N;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IURLGenerator;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\WorkflowEngine\ICheck;
@@ -295,7 +296,8 @@ class ManagerTest extends TestCase {
$this->createMock(ILogger::class),
$this->createMock(\OCP\Share\IManager::class),
$this->createMock(IUserSession::class),
- $this->createMock(ISystemTagManager::class)
+ $this->createMock(ISystemTagManager::class),
+ $this->createMock(IUserManager::class),
])
->setMethodsExcept(['getEvents'])
->getMock();