fix(files_sharing): Switch back event path to be relative to user folder

This is clearly the original intent, the parameter name in ViewOnly is
 $userFolder, and the similar event for single file download uses
 paths relative to user folder as well.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-01-19 11:22:17 +01:00 committed by backportbot[bot]
parent 102c5183e1
commit 7a88cb0709
3 changed files with 9 additions and 4 deletions

View file

@ -48,7 +48,7 @@ class BeforeZipCreatedListener implements IEventListener {
$user = $this->userSession->getUser();
if ($user) {
$viewOnlyHandler = new ViewOnly(
$this->rootFolder
$this->rootFolder->getUserFolder($user->getUID())
);
if (!$viewOnlyHandler->check($pathsToCheck)) {
$event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');

View file

@ -24,7 +24,7 @@ class ViewOnly {
}
/**
* @param string[] $pathsToCheck
* @param string[] $pathsToCheck paths to check, relative to the user folder
* @return bool
*/
public function check(array $pathsToCheck): bool {

View file

@ -21,12 +21,13 @@ use OCP\Files\Folder;
* @since 25.0.0
*/
class BeforeZipCreatedEvent extends Event {
private string $directory;
private ?string $directory = null;
private bool $successful = true;
private ?string $errorMessage = null;
private ?Folder $folder = null;
/**
* @param string|Folder $directory Folder instance, or (deprecated) string path relative to user folder
* @param list<string> $files
* @since 25.0.0
* @since 31.0.0 support `OCP\Files\Folder` as `$directory` parameter - passing a string is deprecated now
@ -37,7 +38,6 @@ class BeforeZipCreatedEvent extends Event {
) {
parent::__construct();
if ($directory instanceof Folder) {
$this->directory = $directory->getPath();
$this->folder = $directory;
} else {
$this->directory = $directory;
@ -53,8 +53,13 @@ class BeforeZipCreatedEvent extends Event {
/**
* @since 25.0.0
* @deprecated 33.0.0 Use getFolder instead and use node API
* @return string returns folder path relative to user folder
*/
public function getDirectory(): string {
if ($this->folder instanceof Folder) {
return preg_replace('|^/[^/]+/files/|', '/', $this->folder->getPath());
}
return $this->directory;
}