Skip to content
Open
Changes from 1 commit
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
38 changes: 20 additions & 18 deletions lib/DAV/GroupFoldersHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;

/**
* WebDAV collection representing a user's group folders home directory.
*
* Serves as a container for all group folders accessible to a specific user,
* providing read-only access to the list of group folders they can access.
* Each child node is a GroupFolderNode representing an individual group folder.
*/
class GroupFoldersHome implements ICollection {
public function __construct(
private array $principalInfo,
Expand All @@ -28,32 +35,27 @@ public function __construct(
}

public function delete(): never {
throw new Forbidden();
throw new Forbidden('Permission denied to delete this folder');
}

public function getName(): string {
[, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
return $name;
}

public function setName($name): never {
public function setName(string $name): never {
throw new Forbidden('Permission denied to rename this folder');
}

public function createFile($name, $data = null): never {
throw new Forbidden('Not allowed to create files in this folder');
public function createFile(string $name, $data = null): never {
throw new Forbidden('Permission denied to create files in this folder');
}

public function createDirectory($name): never {
public function createDirectory(string $name): never {
throw new Forbidden('Permission denied to create folders in this folder');
}

private function getFolder(string $name): ?FolderDefinition {
$storageId = $this->rootFolder->getMountPoint()->getNumericStorageId();
if ($storageId === null) {
return null;
}

$folders = $this->folderManager->getFoldersForUser($this->user);
foreach ($folders as $folder) {
if (basename($folder->mountPoint) === $name) {
Expand All @@ -64,6 +66,11 @@ private function getFolder(string $name): ?FolderDefinition {
return null;
}

/**
* Creates a GroupFolderNode for the given folder definition.
*
* @throws RuntimeException If the filesystem view cannot be obtained
*/
private function getDirectoryForFolder(FolderDefinition $folder): GroupFolderNode {
$userHome = '/' . $this->user->getUID() . '/files';
$node = $this->rootFolder->get($userHome . '/' . $folder->mountPoint);
Expand All @@ -76,9 +83,9 @@ private function getDirectoryForFolder(FolderDefinition $folder): GroupFolderNod
return new GroupFolderNode($view, $node, $folder->id);
}

public function getChild($name): GroupFolderNode {
public function getChild(string $name): GroupFolderNode {
$folder = $this->getFolder($name);
if ($folder) {
if ($folder !== null) {
return $this->getDirectoryForFolder($folder);
}

Expand All @@ -89,11 +96,6 @@ public function getChild($name): GroupFolderNode {
* @return GroupFolderNode[]
*/
public function getChildren(): array {
$storageId = $this->rootFolder->getMountPoint()->getNumericStorageId();
if ($storageId === null) {
return [];
}

Comment on lines -92 to -96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you detail why this check was not needed?

$folders = $this->folderManager->getFoldersForUser($this->user);

// Filter out non top-level folders
Expand All @@ -102,7 +104,7 @@ public function getChildren(): array {
return array_map($this->getDirectoryForFolder(...), $folders);
}

public function childExists($name): bool {
public function childExists(string $name): bool {
return $this->getFolder($name) !== null;
}

Expand Down