Skip to content

Commit dac55c5

Browse files
committed
fix(isLegitimatedForUserId): Setup mountpoints to check file access
This fixes workflows on groupfolders, as it will consider access to files in groupfolders. It also fixes false positives where access to files was limited by other means not taken into account before, e.g. access control. For postDelete events, check for permissions of the parent folder instead, as the file itself no longer exists. Fixes: nextcloud/flow_notifications#71 Signed-off-by: Jonas <[email protected]>
1 parent 6714e51 commit dac55c5

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

apps/workflowengine/lib/Entity/File.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
namespace OCA\WorkflowEngine\Entity;
2828

29+
use OC\Files\Config\UserMountCache;
2930
use OCP\EventDispatcher\Event;
3031
use OCP\EventDispatcher\GenericEvent;
3132
use OCP\Files\InvalidPathException;
@@ -38,7 +39,6 @@
3839
use OCP\IUser;
3940
use OCP\IUserManager;
4041
use OCP\IUserSession;
41-
use OCP\Share\IManager as ShareManager;
4242
use OCP\SystemTag\ISystemTag;
4343
use OCP\SystemTag\ISystemTagManager;
4444
use OCP\SystemTag\MapperEvent;
@@ -65,8 +65,6 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
6565
protected $eventName;
6666
/** @var Event */
6767
protected $event;
68-
/** @var ShareManager */
69-
private $shareManager;
7068
/** @var IUserSession */
7169
private $userSession;
7270
/** @var ISystemTagManager */
@@ -77,25 +75,27 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation {
7775
private $actingUser = null;
7876
/** @var IUserManager */
7977
private $userManager;
78+
/** @var UserMountCache */
79+
private $userMountCache;
8080

8181
public function __construct(
8282
IL10N $l10n,
8383
IURLGenerator $urlGenerator,
8484
IRootFolder $root,
8585
ILogger $logger,
86-
ShareManager $shareManager,
8786
IUserSession $userSession,
8887
ISystemTagManager $tagManager,
89-
IUserManager $userManager
88+
IUserManager $userManager,
89+
UserMountCache $userMountCache
9090
) {
9191
$this->l10n = $l10n;
9292
$this->urlGenerator = $urlGenerator;
9393
$this->root = $root;
9494
$this->logger = $logger;
95-
$this->shareManager = $shareManager;
9695
$this->userSession = $userSession;
9796
$this->tagManager = $tagManager;
9897
$this->userManager = $userManager;
98+
$this->userMountCache = $userMountCache;
9999
}
100100

101101
public function getName(): string {
@@ -140,8 +140,19 @@ public function isLegitimatedForUserId(string $uid): bool {
140140
if ($node->getOwner()->getUID() === $uid) {
141141
return true;
142142
}
143-
$acl = $this->shareManager->getAccessList($node, true, true);
144-
return isset($acl['users']) && array_key_exists($uid, $acl['users']);
143+
$fileId = $node->getId();
144+
$mounts = $this->userMountCache->getMountsForFileId($fileId, $uid);
145+
foreach ($mounts as $mount) {
146+
$userFolder = $this->root->getUserFolder($uid);
147+
if ($this->eventName === self::EVENT_NAMESPACE . 'postDelete') {
148+
// At postDelete, the file no longer exists. Check for parent folder instead.
149+
$fileId = $node->getParentId();
150+
}
151+
if (!empty($userFolder->getById($fileId))) {
152+
return true;
153+
}
154+
}
155+
return false;
145156
} catch (NotFoundException $e) {
146157
return false;
147158
}

apps/workflowengine/tests/ManagerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
namespace OCA\WorkflowEngine\Tests;
2828

29+
use OC\Files\Config\UserMountCache;
2930
use OC\L10N\L10N;
3031
use OCA\WorkflowEngine\Entity\File;
3132
use OCA\WorkflowEngine\Helper\ScopeContext;
@@ -406,8 +407,8 @@ public function testUpdateOperation() {
406407
$this->createMock(ILogger::class),
407408
$this->createMock(\OCP\Share\IManager::class),
408409
$this->createMock(IUserSession::class),
409-
$this->createMock(ISystemTagManager::class),
410410
$this->createMock(IUserManager::class),
411+
$this->createMock(UserMountCache::class),
411412
])
412413
->setMethodsExcept(['getEvents'])
413414
->getMock();

0 commit comments

Comments
 (0)