summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-27 17:22:26 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-28 13:51:21 +0100
commitb3749fbe1690edd64f16337ba01f381f2cf6176b (patch)
tree2ebbb8fd0a9c340657e965d5dfad8d970ebcdc09 /apps/workflowengine/lib
parent7a7a415fdc81b36a27b8a379e83f7f334c8194e6 (diff)
downloadnextcloud-server-b3749fbe1690edd64f16337ba01f381f2cf6176b.tar.gz
nextcloud-server-b3749fbe1690edd64f16337ba01f381f2cf6176b.zip
add convenience interfaces so entities can provide presentable details
the File entity starts with a display text (used by talk) Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/workflowengine/lib')
-rw-r--r--apps/workflowengine/lib/Entity/File.php67
-rw-r--r--apps/workflowengine/lib/Service/RuleMatcher.php7
2 files changed, 71 insertions, 3 deletions
diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php
index 5192100c2c7..4a01535ce0e 100644
--- a/apps/workflowengine/lib/Entity/File.php
+++ b/apps/workflowengine/lib/Entity/File.php
@@ -32,13 +32,19 @@ use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
+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\IDisplayText;
use OCP\WorkflowEngine\GenericEntityEvent;
use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IRuleMatcher;
-class File implements IEntity {
+class File implements IEntity, IDisplayText {
+
+ private const EVENT_NAMESPACE = '\OCP\Files::';
/** @var IL10N */
protected $l10n;
@@ -54,21 +60,28 @@ class File implements IEntity {
protected $event;
/** @var ShareManager */
private $shareManager;
+ /** @var IUserSession */
+ private $userSession;
+ /** @var ISystemTagManager */
+ private $tagManager;
- private const EVENT_NAMESPACE = '\OCP\Files::';
public function __construct(
IL10N $l10n,
IURLGenerator $urlGenerator,
IRootFolder $root,
ILogger $logger,
- ShareManager $shareManager
+ ShareManager $shareManager,
+ IUserSession $userSession,
+ ISystemTagManager $tagManager
) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->root = $root;
$this->logger = $logger;
$this->shareManager = $shareManager;
+ $this->userSession = $userSession;
+ $this->tagManager = $tagManager;
}
public function getName(): string {
@@ -146,4 +159,52 @@ class File implements IEntity {
}
throw new NotFoundException();
}
+
+ public function getDisplayText(int $verbosity = 0): string {
+ $user = $this->userSession->getUser();
+ try {
+ $node = $this->getNode();
+ } catch (NotFoundException $e) {
+ return '';
+ }
+
+ $options = [
+ $user ? $user->getDisplayName() : $this->t('Someone'),
+ $node->getName()
+ ];
+
+ switch ($this->eventName) {
+ case self::EVENT_NAMESPACE . 'postCreate':
+ return $this->l10n->t('%s created %s', $options);
+ case self::EVENT_NAMESPACE . 'postWrite':
+ return $this->l10n->t('%s modified %s', $options);
+ case self::EVENT_NAMESPACE . 'postDelete':
+ return $this->l10n->t('%s deleted %s', $options);
+ case self::EVENT_NAMESPACE . 'postTouch':
+ return $this->l10n->t('%s accessed %s', $options);
+ case self::EVENT_NAMESPACE . 'postRename':
+ return $this->l10n->t('%s renamed %s', $options);
+ case self::EVENT_NAMESPACE . 'postCopy':
+ return $this->l10n->t('%s copied %s', $options);
+ case MapperEvent::EVENT_ASSIGN:
+ $tagNames = [];
+ if($this->event instanceof MapperEvent) {
+ $tagIDs = $this->event->getTags();
+ $tagObjects = $this->tagManager->getTagsByIds($tagIDs);
+ foreach ($tagObjects as $systemTag) {
+ /** @var ISystemTag $systemTag */
+ if($systemTag->isUserVisible()) {
+ $tagNames[] = $systemTag->getName();
+ }
+ }
+ }
+ $filename = array_pop($options);
+ $tagString = implode(', ', $tagNames);
+ if($tagString === '') {
+ return '';
+ }
+ array_push($options, $tagString, $filename);
+ return $this->l10n->t('%s assigned %s to %s', $options);
+ }
+ }
}
diff --git a/apps/workflowengine/lib/Service/RuleMatcher.php b/apps/workflowengine/lib/Service/RuleMatcher.php
index 6f670c65c15..16f0e486aaa 100644
--- a/apps/workflowengine/lib/Service/RuleMatcher.php
+++ b/apps/workflowengine/lib/Service/RuleMatcher.php
@@ -94,6 +94,13 @@ class RuleMatcher implements IRuleMatcher {
$this->entity = $entity;
}
+ public function getEntity(): IEntity {
+ if($this->entity === null) {
+ throw new \LogicException('Entity was not set yet');
+ }
+ return $this->entity;
+ }
+
public function getFlows(bool $returnFirstMatchingOperationOnly = true): array {
if(!$this->operation) {
throw new RuntimeException('Operation is not set');