Skip to content

Commit

Permalink
Handle not logged in users
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Apr 24, 2023
1 parent ea1abc3 commit 6f2d7f0
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions lib/DAV/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,49 @@
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;

class PropFindPlugin extends ServerPlugin {
private Folder $userFolder;
class PropFindPlugin extends ServerPlugin
{
private Folder $userFolder;

public const MOUNT_POINT_PROPERTYNAME = '{http://nextcloud.org/ns}mount-point';
public const GROUP_FOLDER_ID_PROPERTYNAME = '{http://nextcloud.org/ns}group-folder-id';
public const MOUNT_POINT_PROPERTYNAME = '{http://nextcloud.org/ns}mount-point';
public const GROUP_FOLDER_ID_PROPERTYNAME = '{http://nextcloud.org/ns}group-folder-id';

public function __construct(IRootFolder $rootFolder, IUserSession $userSession) {
$this->userFolder = $rootFolder->getUserFolder($userSession->getUser()->getUID());
}
public function __construct(IRootFolder $rootFolder, IUserSession $userSession)
{
$user = $userSession->getUser();
if ($user === null) {
return;
}

$this->userFolder = $rootFolder->getUserFolder($user->getUID());
}

public function getPluginName(): string {
return 'groupFoldersDavPlugin';
}

public function initialize(Server $server): void {
$server->on('propFind', [$this, 'propFind']);
}
public function getPluginName(): string
{
return 'groupFoldersDavPlugin';
}

public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof GroupFolderNode) {
$propFind->handle(
self::MOUNT_POINT_PROPERTYNAME,
fn() => $this->userFolder->getRelativePath($node->getFileInfo()->getMountPoint()->getMountPoint())
);
$propFind->handle(
self::GROUP_FOLDER_ID_PROPERTYNAME,
fn() => $node->getFolderId()
);
}
}
public function initialize(Server $server): void
{
$server->on('propFind', [$this, 'propFind']);
}

public function propFind(PropFind $propFind, INode $node): void
{
if (!isset($this->userFolder)) {
return;
}

if ($node instanceof GroupFolderNode) {
$propFind->handle(
self::MOUNT_POINT_PROPERTYNAME,
fn () => $this->userFolder->getRelativePath($node->getFileInfo()->getMountPoint()->getMountPoint())
);
$propFind->handle(
self::GROUP_FOLDER_ID_PROPERTYNAME,
fn () => $node->getFolderId()
);
}
}
}

0 comments on commit 6f2d7f0

Please sign in to comment.