Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions lib/DAV/LockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function customProperties(PropFind $propFind, INode $node) {

$nodeId = $node->getId();

$propFind->handle(Application::DAV_PROPERTY_LOCK, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());
return $lock instanceof FileLock;
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());

if ($lock === false) {
return null;
Expand All @@ -122,8 +122,8 @@ public function customProperties(PropFind $propFind, INode $node) {
return $lock->getOwner();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_TIME, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_TIME, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());

if ($lock === false) {
return null;
Expand All @@ -132,8 +132,8 @@ public function customProperties(PropFind $propFind, INode $node) {
return $lock->getCreatedAt();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_TIMEOUT, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_TIMEOUT, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());

if ($lock === false) {
return null;
Expand All @@ -142,8 +142,8 @@ public function customProperties(PropFind $propFind, INode $node) {
return $lock->getTimeout();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER_DISPLAYNAME, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER_DISPLAYNAME, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());

if ($lock === false) {
return null;
Expand All @@ -154,8 +154,8 @@ public function customProperties(PropFind $propFind, INode $node) {
return $lock->getDisplayName();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER_TYPE, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER_TYPE, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());

if ($lock === false) {
return null;
Expand All @@ -164,17 +164,17 @@ public function customProperties(PropFind $propFind, INode $node) {
return $lock->getType();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_EDITOR, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_EDITOR, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());
if ($lock === false || $lock->getType() !== ILock::TYPE_APP) {
return null;
}

return $lock->getOwner();
});

$propFind->handle(Application::DAV_PROPERTY_LOCK_TOKEN, function () use ($nodeId) {
$lock = $this->lockService->getLockForNodeId($nodeId);
$propFind->handle(Application::DAV_PROPERTY_LOCK_TOKEN, function () use ($nodeId, $node) {
$lock = $this->lockService->getLockForNodeId($nodeId, $node->getNode());
if ($lock === false) {
return null;
}
Expand Down
13 changes: 8 additions & 5 deletions lib/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Files\Lock\ILock;
use OCP\Files\Lock\LockContext;
use OCP\Files\Lock\OwnerLockedException;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -69,7 +70,7 @@
IUserSession $userSession,
IRequest $request,
LoggerInterface $logger,
private IRootFolder $rootFolder,

Check failure on line 73 in lib/Service/LockService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingDependency

lib/Service/LockService.php:73:3: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)
) {
$this->l10n = $l10n;
$this->userManager = $userManager;
Expand All @@ -88,15 +89,15 @@
*
* @return FileLock|bool
*/
public function getLockForNodeId(int $nodeId) {
public function getLockForNodeId(int $nodeId, ?Node $node = null) {
if (array_key_exists($nodeId, $this->lockCache) && $this->lockCache[$nodeId] !== null) {
return $this->lockCache[$nodeId];
}

try {
$this->lockCache[$nodeId] = $this->getLockFromFileId($nodeId);
} catch (LockNotFoundException) {
$remoteLock = $this->getRemoteLockFromDav($nodeId);
$remoteLock = $this->getRemoteLockFromDav($nodeId, $node);
$this->lockCache[$nodeId] = $remoteLock ?: false;
}

Expand Down Expand Up @@ -399,15 +400,17 @@
$this->locksRequest->removeIds($ids);
}

public function getRemoteLockFromDav(int $nodeId): ?FileLock {
public function getRemoteLockFromDav(int $nodeId, ?Node $node = null): ?FileLock {
try {
$user = $this->userSession->getUser();
if (!$user) {
return null;
}

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$node = $userFolder->getFirstNodeById($nodeId);
if (!$node) {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());

Check failure on line 411 in lib/Service/LockService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingDependency

lib/Service/LockService.php:411:19: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)
$node = $userFolder->getFirstNodeById($nodeId);
}
if (empty($node)) {
return null;
}
Expand Down
Loading