diff options
author | Git'Fellow <12234510+solracsf@users.noreply.github.com> | 2023-11-28 10:14:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 10:14:12 +0100 |
commit | 61d7328cae0a3a8f1ff4a163d763a2dcb62bf74e (patch) | |
tree | 3daac8c75ae9b3ae8d9cb39f9dbce6aa60415842 | |
parent | 9e67ab7fb8c7c2006a8cdfa75088d38d1120f8f0 (diff) | |
download | nextcloud-server-61d7328cae0a3a8f1ff4a163d763a2dcb62bf74e.tar.gz nextcloud-server-61d7328cae0a3a8f1ff4a163d763a2dcb62bf74e.zip |
Check for owner before call getUserFolder
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
-rw-r--r-- | apps/files_versions/lib/Listener/FileEventsListener.php | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index d90283bacc8..5fe41f76e49 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -59,11 +59,10 @@ use OCP\Files\Folder; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IUserSession; use Psr\Log\LoggerInterface; class FileEventsListener implements IEventListener { - private IRootFolder $rootFolder; - private IVersionManager $versionManager; /** * @var array<int, array> */ @@ -76,19 +75,14 @@ class FileEventsListener implements IEventListener { * @var array<string, Node> */ private array $versionsDeleted = []; - private IMimeTypeLoader $mimeTypeLoader; - private LoggerInterface $logger; public function __construct( - IRootFolder $rootFolder, - IVersionManager $versionManager, - IMimeTypeLoader $mimeTypeLoader, - LoggerInterface $logger, + private IRootFolder $rootFolder, + private IVersionManager $versionManager, + private IMimeTypeLoader $mimeTypeLoader, + private IUserSession $userSession, + private LoggerInterface $logger, ) { - $this->rootFolder = $rootFolder; - $this->versionManager = $versionManager; - $this->mimeTypeLoader = $mimeTypeLoader; - $this->logger = $logger; } public function handle(Event $event): void { @@ -351,17 +345,23 @@ class FileEventsListener implements IEventListener { /** * Retrieve the path relative to the current user root folder. - * If no user is connected, use the node's owner. + * If no user is connected, try to use the node's owner. */ private function getPathForNode(Node $node): ?string { - try { + $user = $this->userSession->getUser()?->getUID(); + if ($user) { return $this->rootFolder - ->getUserFolder(\OC_User::getUser()) + ->getUserFolder($user) ->getRelativePath($node->getPath()); - } catch (\Throwable $ex) { + } + + $owner = $node->getOwner()?->getUid(); + if ($owner) { return $this->rootFolder - ->getUserFolder($node->getOwner()->getUid()) + ->getUserFolder($owner) ->getRelativePath($node->getPath()); } + + return null; } } |