2015-10-21 09:06:48 -04:00
|
|
|
<?php
|
2024-05-27 11:39:07 -04:00
|
|
|
|
2016-01-12 09:02:16 -05:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-01-12 09:02:16 -05:00
|
|
|
*/
|
2015-10-21 09:06:48 -04:00
|
|
|
namespace OCA\DAV\Files;
|
|
|
|
|
|
2018-05-24 08:17:53 -04:00
|
|
|
use OCP\Files\FileInfo;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\Server;
|
2016-10-20 06:52:57 -04:00
|
|
|
use Sabre\DAV\INode;
|
2016-09-08 06:56:48 -04:00
|
|
|
use Sabre\DAV\SimpleCollection;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Sabre\DAVACL\AbstractPrincipalCollection;
|
2015-10-21 09:06:48 -04:00
|
|
|
|
|
|
|
|
class RootCollection extends AbstractPrincipalCollection {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method returns a node for a principal.
|
|
|
|
|
*
|
|
|
|
|
* The passed array contains principal information, and is guaranteed to
|
|
|
|
|
* at least contain a uri item. Other properties may or may not be
|
|
|
|
|
* supplied by the authentication backend.
|
|
|
|
|
*
|
|
|
|
|
* @param array $principalInfo
|
2016-09-08 06:56:48 -04:00
|
|
|
* @return INode
|
2015-10-21 09:06:48 -04:00
|
|
|
*/
|
2020-04-10 10:51:06 -04:00
|
|
|
public function getChildForPrincipal(array $principalInfo) {
|
2021-01-12 04:15:48 -05:00
|
|
|
[,$name] = \Sabre\Uri\split($principalInfo['uri']);
|
2025-02-03 09:34:01 -05:00
|
|
|
$user = Server::get(IUserSession::class)->getUser();
|
2016-10-13 06:15:10 -04:00
|
|
|
if (is_null($user) || $name !== $user->getUID()) {
|
2016-09-08 06:56:48 -04:00
|
|
|
// a user is only allowed to see their own home contents, so in case another collection
|
|
|
|
|
// is accessed, we return a simple empty collection for now
|
|
|
|
|
// in the future this could be considered to be used for accessing shared files
|
|
|
|
|
return new SimpleCollection($name);
|
|
|
|
|
}
|
2018-05-24 08:17:53 -04:00
|
|
|
$userFolder = \OC::$server->getUserFolder();
|
|
|
|
|
if (!($userFolder instanceof FileInfo)) {
|
|
|
|
|
throw new \Exception('Home does not exist');
|
|
|
|
|
}
|
|
|
|
|
return new FilesHome($principalInfo, $userFolder);
|
2015-10-21 09:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-10 10:51:06 -04:00
|
|
|
public function getName() {
|
2015-10-21 09:06:48 -04:00
|
|
|
return 'files';
|
|
|
|
|
}
|
|
|
|
|
}
|