Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files_versions): Check for user and owner before call getUserFolder #41749

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
36 changes: 16 additions & 20 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@
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>
*/
Expand All @@ -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 {
Expand Down Expand Up @@ -354,18 +348,20 @@ public function pre_renameOrCopy_hook(Node $source, Node $target): void {
* 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)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
->getRelativePath($node->getPath());
} catch (\Throwable $ex) {
$owner = $node->getOwner();
if ($owner === null) {
return null;
}
}

$owner = $node->getOwner()?->getUid();
if ($owner) {
return $this->rootFolder
->getUserFolder($owner->getUid())
->getUserFolder($owner)
->getRelativePath($node->getPath());
}

return null;
}
}
Loading