aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib/Entity/File.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workflowengine/lib/Entity/File.php')
-rw-r--r--apps/workflowengine/lib/Entity/File.php92
1 files changed, 33 insertions, 59 deletions
diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php
index 3f09fcd24a1..64d552e1737 100644
--- a/apps/workflowengine/lib/Entity/File.php
+++ b/apps/workflowengine/lib/Entity/File.php
@@ -3,42 +3,24 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WorkflowEngine\Entity;
+use OC\Files\Config\UserMountCache;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\GenericEvent;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
+use OCP\Files\Mount\IMountManager;
use OCP\Files\Node;
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;
@@ -52,50 +34,28 @@ use OCP\WorkflowEngine\IRuleMatcher;
class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
private const EVENT_NAMESPACE = '\OCP\Files::';
-
- /** @var IL10N */
- protected $l10n;
- /** @var IURLGenerator */
- protected $urlGenerator;
- /** @var IRootFolder */
- protected $root;
- /** @var ILogger */
- protected $logger;
/** @var string */
protected $eventName;
/** @var Event */
protected $event;
- /** @var ShareManager */
- private $shareManager;
- /** @var IUserSession */
- private $userSession;
- /** @var ISystemTagManager */
- private $tagManager;
/** @var ?Node */
private $node;
/** @var ?IUser */
private $actingUser = null;
- /** @var IUserManager */
- private $userManager;
+ /** @var UserMountCache */
+ private $userMountCache;
public function __construct(
- IL10N $l10n,
- IURLGenerator $urlGenerator,
- IRootFolder $root,
- ILogger $logger,
- ShareManager $shareManager,
- IUserSession $userSession,
- ISystemTagManager $tagManager,
- IUserManager $userManager
+ protected IL10N $l10n,
+ protected IURLGenerator $urlGenerator,
+ protected IRootFolder $root,
+ private IUserSession $userSession,
+ private ISystemTagManager $tagManager,
+ private IUserManager $userManager,
+ UserMountCache $userMountCache,
+ private IMountManager $mountManager,
) {
- $this->l10n = $l10n;
- $this->urlGenerator = $urlGenerator;
- $this->root = $root;
- $this->logger = $logger;
- $this->shareManager = $shareManager;
- $this->userSession = $userSession;
- $this->tagManager = $tagManager;
- $this->userManager = $userManager;
+ $this->userMountCache = $userMountCache;
}
public function getName(): string {
@@ -134,14 +94,28 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
}
}
- public function isLegitimatedForUserId(string $uid): bool {
+ public function isLegitimatedForUserId(string $userId): bool {
try {
$node = $this->getNode();
- if ($node->getOwner()->getUID() === $uid) {
+ if ($node->getOwner()?->getUID() === $userId) {
return true;
}
- $acl = $this->shareManager->getAccessList($node, true, true);
- return isset($acl['users']) && array_key_exists($uid, $acl['users']);
+
+ if ($this->eventName === self::EVENT_NAMESPACE . 'postDelete') {
+ // At postDelete, the file no longer exists. Check for parent folder instead.
+ $fileId = $node->getParentId();
+ } else {
+ $fileId = $node->getId();
+ }
+
+ $mountInfos = $this->userMountCache->getMountsForFileId($fileId, $userId);
+ foreach ($mountInfos as $mountInfo) {
+ $mount = $this->mountManager->getMountFromMountInfo($mountInfo);
+ if ($mount && $mount->getStorage() && !empty($mount->getStorage()->getCache()->get($fileId))) {
+ return true;
+ }
+ }
+ return false;
} catch (NotFoundException $e) {
return false;
}