2018-04-16 08:14:31 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-04-25 14:24:23 -04:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-04-16 08:14:31 -04:00
|
|
|
/**
|
2024-06-02 09:26:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-04-16 08:14:31 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Files_Trashbin\Sabre;
|
|
|
|
|
|
2018-09-10 08:40:35 -04:00
|
|
|
use OCA\Files_Trashbin\Trash\ITrashManager;
|
2018-05-08 14:52:14 -04:00
|
|
|
use OCP\IConfig;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\Server;
|
2018-04-16 08:14:31 -04:00
|
|
|
use Sabre\DAV\INode;
|
|
|
|
|
use Sabre\DAVACL\AbstractPrincipalCollection;
|
|
|
|
|
use Sabre\DAVACL\PrincipalBackend;
|
|
|
|
|
|
|
|
|
|
class RootCollection extends AbstractPrincipalCollection {
|
2018-09-10 08:40:35 -04:00
|
|
|
public function __construct(
|
2024-10-18 06:04:22 -04:00
|
|
|
private ITrashManager $trashManager,
|
2018-09-10 08:40:35 -04:00
|
|
|
PrincipalBackend\BackendInterface $principalBackend,
|
|
|
|
|
IConfig $config,
|
|
|
|
|
) {
|
2018-04-16 08:14:31 -04:00
|
|
|
parent::__construct($principalBackend, 'principals/users');
|
2018-05-08 14:52:14 -04:00
|
|
|
$this->disableListing = !$config->getSystemValue('debug', false);
|
2018-04-16 08:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* @return INode
|
|
|
|
|
*/
|
2018-04-25 14:24:23 -04:00
|
|
|
public function getChildForPrincipal(array $principalInfo): TrashHome {
|
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();
|
2018-04-16 08:14:31 -04:00
|
|
|
if (is_null($user) || $name !== $user->getUID()) {
|
|
|
|
|
throw new \Sabre\DAV\Exception\Forbidden();
|
|
|
|
|
}
|
2018-09-10 08:40:35 -04:00
|
|
|
return new TrashHome($principalInfo, $this->trashManager, $user);
|
2018-04-16 08:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-25 14:24:23 -04:00
|
|
|
public function getName(): string {
|
2018-04-16 08:14:31 -04:00
|
|
|
return 'trashbin';
|
|
|
|
|
}
|
|
|
|
|
}
|