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

[stable23] always use the default fs owner when storing versions #33971

Merged
merged 1 commit into from
Sep 27, 2022
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
41 changes: 27 additions & 14 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OC_User;
use OC\Files\Filesystem;
use OC\Files\View;
use OCA\Files_Sharing\SharedMount;
use OCA\Files_Versions\AppInfo\Application;
use OCA\Files_Versions\Command\Expire;
use OCA\Files_Versions\Events\CreateVersionEvent;
Expand Down Expand Up @@ -188,33 +189,45 @@ public static function store($filename) {
return false;
}

[$uid, $filename] = self::getUidAndFilename($filename);
// since hook paths are always relative to the "default filesystem view"
// we always use the owner from there to get the full node
$uid = Filesystem::getView()->getOwner('');

$files_view = new View('/'.$uid .'/files');
/** @var IRootFolder $rootFolder */
$rootFolder = \OC::$server->get(IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($uid);

$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$fileInfo = $files_view->getFileInfo($filename);
$id = $fileInfo->getId();
$nodes = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->getById($id);
foreach ($nodes as $node) {
$event = new CreateVersionEvent($node);
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
if ($event->shouldCreateVersion() === false) {
return false;
try {
$file = $userFolder->get($filename);
} catch (NotFoundException $e) {
return false;
}

$mount = $file->getMountPoint();
if ($mount instanceof SharedMount) {
$ownerFolder = $rootFolder->getUserFolder($mount->getShare()->getShareOwner());
$ownerNodes = $ownerFolder->getById($file->getId());
if (count($ownerNodes)) {
$file = current($ownerNodes);
}
}

// no use making versions for empty files
if ($fileInfo->getSize() === 0) {
if ($file->getSize() === 0) {
return false;
}

$event = new CreateVersionEvent($file);
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
if ($event->shouldCreateVersion() === false) {
return false;
}

/** @var IVersionManager $versionManager */
$versionManager = \OC::$server->get(IVersionManager::class);
$userManager = \OC::$server->get(IUserManager::class);
$user = $userManager->get($uid);

$versionManager->createVersion($user, $fileInfo);
$versionManager->createVersion($file->getOwner(), $file);
}


Expand Down