Skip to content

Commit 7a88cb0

Browse files
come-ncbackportbot[bot]
authored andcommitted
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>
1 parent 102c518 commit 7a88cb0

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

apps/files_sharing/lib/Listener/BeforeZipCreatedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(Event $event): void {
4848
$user = $this->userSession->getUser();
4949
if ($user) {
5050
$viewOnlyHandler = new ViewOnly(
51-
$this->rootFolder
51+
$this->rootFolder->getUserFolder($user->getUID())
5252
);
5353
if (!$viewOnlyHandler->check($pathsToCheck)) {
5454
$event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');

apps/files_sharing/lib/ViewOnly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
}
2525

2626
/**
27-
* @param string[] $pathsToCheck
27+
* @param string[] $pathsToCheck paths to check, relative to the user folder
2828
* @return bool
2929
*/
3030
public function check(array $pathsToCheck): bool {

lib/public/Files/Events/BeforeZipCreatedEvent.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
* @since 25.0.0
2222
*/
2323
class BeforeZipCreatedEvent extends Event {
24-
private string $directory;
24+
private ?string $directory = null;
2525
private bool $successful = true;
2626
private ?string $errorMessage = null;
2727
private ?Folder $folder = null;
2828

2929
/**
30+
* @param string|Folder $directory Folder instance, or (deprecated) string path relative to user folder
3031
* @param list<string> $files
3132
* @since 25.0.0
3233
* @since 31.0.0 support `OCP\Files\Folder` as `$directory` parameter - passing a string is deprecated now
@@ -37,7 +38,6 @@ public function __construct(
3738
) {
3839
parent::__construct();
3940
if ($directory instanceof Folder) {
40-
$this->directory = $directory->getPath();
4141
$this->folder = $directory;
4242
} else {
4343
$this->directory = $directory;
@@ -53,8 +53,13 @@ public function getFolder(): ?Folder {
5353

5454
/**
5555
* @since 25.0.0
56+
* @deprecated 33.0.0 Use getFolder instead and use node API
57+
* @return string returns folder path relative to user folder
5658
*/
5759
public function getDirectory(): string {
60+
if ($this->folder instanceof Folder) {
61+
return preg_replace('|^/[^/]+/files/|', '/', $this->folder->getPath());
62+
}
5863
return $this->directory;
5964
}
6065

0 commit comments

Comments
 (0)