- Remove unused class AppEnabledPlugin - Add more type hinting when possible Signed-off-by: Carl Schwan <carl@carlschwan.eu>tags/v25.0.0beta1
@@ -38,6 +38,7 @@ use OCA\DAV\Connector\Sabre\Principal; | |||
use OCP\App\IAppManager; | |||
use Psr\Log\LoggerInterface; | |||
use Sabre\CardDAV\Plugin; | |||
use Psr\Log\LoggerInterface; | |||
$authBackend = new Auth( | |||
\OC::$server->getSession(), |
@@ -29,6 +29,9 @@ | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
use Psr\Log\LoggerInterface; | |||
// load needed apps | |||
$RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; | |||
@@ -48,7 +51,7 @@ $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); | |||
$serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( | |||
\OC::$server->getConfig(), | |||
\OC::$server->get(Psr\Log\LoggerInterface::class), | |||
\OC::$server->get(LoggerInterface::class), | |||
\OC::$server->getDatabaseConnection(), | |||
\OC::$server->getUserSession(), | |||
\OC::$server->getMountManager(), |
@@ -28,6 +28,8 @@ | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
use Psr\Log\LoggerInterface; | |||
// no php execution timeout for webdav | |||
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { | |||
@set_time_limit(0); | |||
@@ -39,7 +41,7 @@ ignore_user_abort(true); | |||
$serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( | |||
\OC::$server->getConfig(), | |||
\OC::$server->get(Psr\Log\LoggerInterface::class), | |||
\OC::$server->get(LoggerInterface::class), | |||
\OC::$server->getDatabaseConnection(), | |||
\OC::$server->getUserSession(), | |||
\OC::$server->getMountManager(), |
@@ -139,7 +139,6 @@ return array( | |||
'OCA\\DAV\\Connector\\LegacyDAVACL' => $baseDir . '/../lib/Connector/LegacyDAVACL.php', | |||
'OCA\\DAV\\Connector\\PublicAuth' => $baseDir . '/../lib/Connector/PublicAuth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => $baseDir . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php', | |||
'OCA\\DAV\\Connector\\Sabre\\AppEnabledPlugin' => $baseDir . '/../lib/Connector/Sabre/AppEnabledPlugin.php', | |||
'OCA\\DAV\\Connector\\Sabre\\Auth' => $baseDir . '/../lib/Connector/Sabre/Auth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\BearerAuth' => $baseDir . '/../lib/Connector/Sabre/BearerAuth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\BlockLegacyClientPlugin' => $baseDir . '/../lib/Connector/Sabre/BlockLegacyClientPlugin.php', |
@@ -154,7 +154,6 @@ class ComposerStaticInitDAV | |||
'OCA\\DAV\\Connector\\LegacyDAVACL' => __DIR__ . '/..' . '/../lib/Connector/LegacyDAVACL.php', | |||
'OCA\\DAV\\Connector\\PublicAuth' => __DIR__ . '/..' . '/../lib/Connector/PublicAuth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php', | |||
'OCA\\DAV\\Connector\\Sabre\\AppEnabledPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AppEnabledPlugin.php', | |||
'OCA\\DAV\\Connector\\Sabre\\Auth' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Auth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\BearerAuth' => __DIR__ . '/..' . '/../lib/Connector/Sabre/BearerAuth.php', | |||
'OCA\\DAV\\Connector\\Sabre\\BlockLegacyClientPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/BlockLegacyClientPlugin.php', |
@@ -23,11 +23,11 @@ | |||
namespace OCA\DAV\CalDAV\ICSExportPlugin; | |||
use OCP\IConfig; | |||
use Psr\Log\LoggerInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
use Sabre\VObject\DateTimeParser; | |||
use Sabre\VObject\InvalidDataException; | |||
use Sabre\VObject\Property\ICalendar\Duration; | |||
use Psr\Log\LoggerInterface; | |||
/** | |||
* Class ICSExportPlugin | |||
@@ -35,10 +35,7 @@ use Sabre\VObject\Property\ICalendar\Duration; | |||
* @package OCA\DAV\CalDAV\ICSExportPlugin | |||
*/ | |||
class ICSExportPlugin extends \Sabre\CalDAV\ICSExportPlugin { | |||
/** @var IConfig */ | |||
private $config; | |||
private IConfig $config; | |||
private LoggerInterface $logger; | |||
/** @var string */ |
@@ -37,6 +37,7 @@ use OCA\DAV\RootCollection; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use Psr\Log\LoggerInterface; | |||
use Sabre\VObject\ITip\Message; | |||
use Psr\Log\LoggerInterface; | |||
class InvitationResponseServer { | |||
@@ -100,7 +101,7 @@ class InvitationResponseServer { | |||
)); | |||
// wait with registering these until auth is handled and the filesystem is setup | |||
$this->server->on('beforeMethod:*', function () use ($root) { | |||
$this->server->on('beforeMethod:*', function () use ($root): void { | |||
// register plugins from apps | |||
$pluginManager = new PluginManager( | |||
\OC::$server, |
@@ -34,12 +34,12 @@ use OCP\Files\NotFoundException; | |||
use OCP\Files\NotPermittedException; | |||
use OCP\Files\SimpleFS\ISimpleFile; | |||
use OCP\Files\SimpleFS\ISimpleFolder; | |||
use Psr\Log\LoggerInterface; | |||
use Sabre\CardDAV\Card; | |||
use Sabre\VObject\Document; | |||
use Sabre\VObject\Parameter; | |||
use Sabre\VObject\Property\Binary; | |||
use Sabre\VObject\Reader; | |||
use Psr\Log\LoggerInterface; | |||
class PhotoCache { | |||
@@ -51,9 +51,7 @@ class PhotoCache { | |||
'image/vnd.microsoft.icon' => 'ico', | |||
]; | |||
/** @var IAppData */ | |||
protected $appData; | |||
protected IAppData $appData; | |||
protected LoggerInterface $logger; | |||
/** | |||
@@ -91,17 +89,11 @@ class PhotoCache { | |||
return $this->getFile($folder, $size); | |||
} | |||
/** | |||
* @param ISimpleFolder $folder | |||
* @return bool | |||
*/ | |||
private function isEmpty(ISimpleFolder $folder) { | |||
private function isEmpty(ISimpleFolder $folder): bool { | |||
return $folder->getDirectoryListing() === []; | |||
} | |||
/** | |||
* @param ISimpleFolder $folder | |||
* @param Card $card | |||
* @throws NotPermittedException | |||
*/ | |||
private function init(ISimpleFolder $folder, Card $card): void { | |||
@@ -124,11 +116,11 @@ class PhotoCache { | |||
$file->putContent($data['body']); | |||
} | |||
private function hasPhoto(ISimpleFolder $folder) { | |||
private function hasPhoto(ISimpleFolder $folder): bool { | |||
return !$folder->fileExists('nophoto'); | |||
} | |||
private function getFile(ISimpleFolder $folder, $size) { | |||
private function getFile(ISimpleFolder $folder, int $size): ISimpleFile { | |||
$ext = $this->getExtension($folder); | |||
if ($size === -1) { | |||
@@ -189,8 +181,6 @@ class PhotoCache { | |||
/** | |||
* Get the extension of the avatar. If there is no avatar throw Exception | |||
* | |||
* @param ISimpleFolder $folder | |||
* @return string | |||
* @throws NotFoundException | |||
*/ | |||
private function getExtension(ISimpleFolder $folder): string { | |||
@@ -205,7 +195,7 @@ class PhotoCache { | |||
/** | |||
* @param Card $node | |||
* @return bool|array{body: string, Content-Type: string} | |||
* @return false|array{body: string, Content-Type: string} | |||
*/ | |||
private function getPhoto(Card $node) { | |||
try { | |||
@@ -220,8 +210,7 @@ class PhotoCache { | |||
} | |||
/** | |||
* @param Document $vObject | |||
* @return bool|array{body: string, Content-Type: string} | |||
* @return false|array{body: string, Content-Type: string} | |||
*/ | |||
public function getPhotoFromVObject(Document $vObject) { | |||
try { | |||
@@ -265,11 +254,7 @@ class PhotoCache { | |||
return false; | |||
} | |||
/** | |||
* @param string $cardData | |||
* @return \Sabre\VObject\Document | |||
*/ | |||
private function readCard($cardData) { | |||
private function readCard(string $cardData): Document { | |||
return Reader::read($cardData); | |||
} | |||
@@ -44,28 +44,12 @@ use Sabre\DAV\Auth\Backend\AbstractBasic; | |||
*/ | |||
class PublicAuth extends AbstractBasic { | |||
private const BRUTEFORCE_ACTION = 'public_webdav_auth'; | |||
private IShare $share; | |||
private IManager $shareManager; | |||
private ISession $session; | |||
private IRequest $request; | |||
private Throttler $throttler; | |||
/** @var \OCP\Share\IShare */ | |||
private $share; | |||
/** @var IManager */ | |||
private $shareManager; | |||
/** @var ISession */ | |||
private $session; | |||
/** @var IRequest */ | |||
private $request; | |||
/** @var Throttler */ | |||
private $throttler; | |||
/** | |||
* @param IRequest $request | |||
* @param IManager $shareManager | |||
* @param ISession $session | |||
* @param Throttler $throttler | |||
*/ | |||
public function __construct(IRequest $request, | |||
IManager $shareManager, | |||
ISession $session, | |||
@@ -88,7 +72,6 @@ class PublicAuth extends AbstractBasic { | |||
* | |||
* @param string $username | |||
* @param string $password | |||
* | |||
* @return bool | |||
* @throws \Sabre\DAV\Exception\NotAuthenticated | |||
*/ | |||
@@ -133,15 +116,11 @@ class PublicAuth extends AbstractBasic { | |||
$this->throttler->registerAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress()); | |||
return false; | |||
} | |||
} else { | |||
return true; | |||
} | |||
return true; | |||
} | |||
/** | |||
* @return \OCP\Share\IShare | |||
*/ | |||
public function getShare() { | |||
public function getShare(): IShare { | |||
return $this->share; | |||
} | |||
} |
@@ -1,88 +0,0 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Georg Ehrke <oc.list@georgehrke.com> | |||
* @author Robin Appelman <robin@icewind.nl> | |||
* @author Thomas Müller <thomas.mueller@tmit.eu> | |||
* | |||
* @license AGPL-3.0 | |||
* | |||
* This code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License, version 3, | |||
* as published by the Free Software Foundation. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License, version 3, | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
namespace OCA\DAV\Connector\Sabre; | |||
use OCP\App\IAppManager; | |||
use Sabre\DAV\Exception\Forbidden; | |||
use Sabre\DAV\ServerPlugin; | |||
/** | |||
* Plugin to check if an app is enabled for the current user | |||
*/ | |||
class AppEnabledPlugin extends ServerPlugin { | |||
/** | |||
* Reference to main server object | |||
* | |||
* @var \Sabre\DAV\Server | |||
*/ | |||
private $server; | |||
/** | |||
* @var string | |||
*/ | |||
private $app; | |||
/** | |||
* @var \OCP\App\IAppManager | |||
*/ | |||
private $appManager; | |||
/** | |||
* @param string $app | |||
* @param \OCP\App\IAppManager $appManager | |||
*/ | |||
public function __construct($app, IAppManager $appManager) { | |||
$this->app = $app; | |||
$this->appManager = $appManager; | |||
} | |||
/** | |||
* This initializes the plugin. | |||
* | |||
* This function is called by \Sabre\DAV\Server, after | |||
* addPlugin is called. | |||
* | |||
* This method should set up the required event subscriptions. | |||
* | |||
* @param \Sabre\DAV\Server $server | |||
* @return void | |||
*/ | |||
public function initialize(\Sabre\DAV\Server $server) { | |||
$this->server = $server; | |||
$this->server->on('beforeMethod:*', [$this, 'checkAppEnabled'], 30); | |||
} | |||
/** | |||
* This method is called before any HTTP after auth and checks if the user has access to the app | |||
* | |||
* @throws \Sabre\DAV\Exception\Forbidden | |||
* @return bool | |||
*/ | |||
public function checkAppEnabled() { | |||
if (!$this->appManager->isEnabledForUser($this->app)) { | |||
throw new Forbidden(); | |||
} | |||
} | |||
} |
@@ -51,33 +51,19 @@ use Sabre\HTTP\ResponseInterface; | |||
class Auth extends AbstractBasic { | |||
public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; | |||
/** @var ISession */ | |||
private $session; | |||
/** @var Session */ | |||
private $userSession; | |||
/** @var IRequest */ | |||
private $request; | |||
/** @var string */ | |||
private $currentUser; | |||
/** @var Manager */ | |||
private $twoFactorManager; | |||
/** @var Throttler */ | |||
private $throttler; | |||
private ISession $session; | |||
private Session $userSession; | |||
private IRequest $request; | |||
private string $currentUser; | |||
private Manager $twoFactorManager; | |||
private Throttler $throttler; | |||
/** | |||
* @param ISession $session | |||
* @param Session $userSession | |||
* @param IRequest $request | |||
* @param Manager $twoFactorManager | |||
* @param Throttler $throttler | |||
* @param string $principalPrefix | |||
*/ | |||
public function __construct(ISession $session, | |||
Session $userSession, | |||
IRequest $request, | |||
Manager $twoFactorManager, | |||
Throttler $throttler, | |||
$principalPrefix = 'principals/users/') { | |||
string $principalPrefix = 'principals/users/') { | |||
$this->session = $session; | |||
$this->userSession = $userSession; | |||
$this->twoFactorManager = $twoFactorManager; | |||
@@ -97,11 +83,8 @@ class Auth extends AbstractBasic { | |||
* account was changed. | |||
* | |||
* @see https://github.com/owncloud/core/issues/13245 | |||
* | |||
* @param string $username | |||
* @return bool | |||
*/ | |||
public function isDavAuthenticated($username) { | |||
public function isDavAuthenticated(string $username): bool { | |||
return !is_null($this->session->get(self::DAV_AUTHENTICATED)) && | |||
$this->session->get(self::DAV_AUTHENTICATED) === $username; | |||
} | |||
@@ -144,9 +127,7 @@ class Auth extends AbstractBasic { | |||
} | |||
/** | |||
* @param RequestInterface $request | |||
* @param ResponseInterface $response | |||
* @return array | |||
* @return array{bool, string} | |||
* @throws NotAuthenticated | |||
* @throws ServiceUnavailable | |||
*/ | |||
@@ -165,10 +146,8 @@ class Auth extends AbstractBasic { | |||
/** | |||
* Checks whether a CSRF check is required on the request | |||
* | |||
* @return bool | |||
*/ | |||
private function requiresCSRFCheck() { | |||
private function requiresCSRFCheck(): bool { | |||
// GET requires no check at all | |||
if ($this->request->getMethod() === 'GET') { | |||
return false; | |||
@@ -203,12 +182,10 @@ class Auth extends AbstractBasic { | |||
} | |||
/** | |||
* @param RequestInterface $request | |||
* @param ResponseInterface $response | |||
* @return array | |||
* @return array{bool, string} | |||
* @throws NotAuthenticated | |||
*/ | |||
private function auth(RequestInterface $request, ResponseInterface $response) { | |||
private function auth(RequestInterface $request, ResponseInterface $response): array { | |||
$forcedLogout = false; | |||
if (!$this->request->passesCSRFCheck() && |
@@ -31,21 +31,11 @@ use Sabre\HTTP\RequestInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
class BearerAuth extends AbstractBearer { | |||
/** @var IUserSession */ | |||
private $userSession; | |||
/** @var ISession */ | |||
private $session; | |||
/** @var IRequest */ | |||
private $request; | |||
/** @var string */ | |||
private $principalPrefix; | |||
private IUserSession $userSession; | |||
private ISession $session; | |||
private IRequest $request; | |||
private string $principalPrefix; | |||
/** | |||
* @param IUserSession $userSession | |||
* @param ISession $session | |||
* @param string $principalPrefix | |||
* @param IRequest $request | |||
*/ | |||
public function __construct(IUserSession $userSession, | |||
ISession $session, | |||
IRequest $request, | |||
@@ -90,7 +80,7 @@ class BearerAuth extends AbstractBearer { | |||
* @param RequestInterface $request | |||
* @param ResponseInterface $response | |||
*/ | |||
public function challenge(RequestInterface $request, ResponseInterface $response) { | |||
public function challenge(RequestInterface $request, ResponseInterface $response): void { | |||
$response->setStatus(401); | |||
} | |||
} |
@@ -28,6 +28,7 @@ namespace OCA\DAV\Connector\Sabre; | |||
use OCP\IConfig; | |||
use Sabre\DAV\ServerPlugin; | |||
use Sabre\HTTP\RequestInterface; | |||
use Sabre\DAV\Server; | |||
/** | |||
* Class BlockLegacyClientPlugin is used to detect old legacy sync clients and | |||
@@ -36,23 +37,17 @@ use Sabre\HTTP\RequestInterface; | |||
* @package OCA\DAV\Connector\Sabre | |||
*/ | |||
class BlockLegacyClientPlugin extends ServerPlugin { | |||
/** @var \Sabre\DAV\Server */ | |||
protected $server; | |||
/** @var IConfig */ | |||
protected $config; | |||
protected Server $server; | |||
protected IConfig $config; | |||
/** | |||
* @param IConfig $config | |||
*/ | |||
public function __construct(IConfig $config) { | |||
$this->config = $config; | |||
} | |||
/** | |||
* @param \Sabre\DAV\Server $server | |||
* @return void | |||
*/ | |||
public function initialize(\Sabre\DAV\Server $server) { | |||
public function initialize(Server $server) { | |||
$this->server = $server; | |||
$this->server->on('beforeMethod:*', [$this, 'beforeHandler'], 200); | |||
} |
@@ -28,17 +28,18 @@ use Sabre\DAV\Tree; | |||
class CachingTree extends Tree { | |||
/** | |||
* Store a node in the cache | |||
* | |||
* @param Node $node | |||
* @param null|string $path | |||
*/ | |||
public function cacheNode(Node $node, $path = null) { | |||
public function cacheNode(Node $node, ?string $path = null): void { | |||
if (is_null($path)) { | |||
$path = $node->getPath(); | |||
} | |||
$this->cache[trim($path, '/')] = $node; | |||
} | |||
/** | |||
* @param string $path | |||
* @return void | |||
*/ | |||
public function markDirty($path) { | |||
// We don't care enough about sub-paths | |||
// flushing the entire cache |
@@ -35,12 +35,9 @@ class ChecksumList implements XmlSerializable { | |||
public const NS_OWNCLOUD = 'http://owncloud.org/ns'; | |||
/** @var string[] of TYPE:CHECKSUM */ | |||
private $checksums; | |||
private array $checksums; | |||
/** | |||
* @param string $checksum | |||
*/ | |||
public function __construct($checksum) { | |||
public function __construct(string $checksum) { | |||
$this->checksums = explode(',', $checksum); | |||
} | |||
@@ -26,14 +26,12 @@ namespace OCA\DAV\Connector\Sabre; | |||
use Sabre\DAV\ServerPlugin; | |||
use Sabre\HTTP\RequestInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
use Sabre\DAV\Server; | |||
class ChecksumUpdatePlugin extends ServerPlugin { | |||
/** | |||
* @var \Sabre\DAV\Server | |||
*/ | |||
protected $server; | |||
protected Server $server; | |||
public function initialize(\Sabre\DAV\Server $server) { | |||
public function initialize(Server $server) { | |||
$this->server = $server; | |||
$server->on('method:PATCH', [$this, 'httpPatch']); | |||
} | |||
@@ -42,6 +40,7 @@ class ChecksumUpdatePlugin extends ServerPlugin { | |||
return 'checksumupdate'; | |||
} | |||
/** @return string[] */ | |||
public function getHTTPMethods($path): array { | |||
$tree = $this->server->tree; | |||
@@ -55,6 +54,7 @@ class ChecksumUpdatePlugin extends ServerPlugin { | |||
return []; | |||
} | |||
/** @return string[] */ | |||
public function getFeatures(): array { | |||
return ['nextcloud-checksum-update']; | |||
} |
@@ -29,22 +29,17 @@ use OCP\Comments\ICommentsManager; | |||
use OCP\IUserSession; | |||
use Sabre\DAV\PropFind; | |||
use Sabre\DAV\ServerPlugin; | |||
use Sabre\DAV\Server; | |||
class CommentPropertiesPlugin extends ServerPlugin { | |||
public const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; | |||
public const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; | |||
public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; | |||
/** @var \Sabre\DAV\Server */ | |||
protected $server; | |||
/** @var ICommentsManager */ | |||
private $commentsManager; | |||
/** @var IUserSession */ | |||
private $userSession; | |||
private $cachedUnreadCount = []; | |||
protected Server $server; | |||
private ICommentsManager $commentsManager; | |||
private IUserSession $userSession; | |||
private array $cachedUnreadCount = []; | |||
public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { | |||
$this->commentsManager = $commentsManager; | |||
@@ -67,7 +62,7 @@ class CommentPropertiesPlugin extends ServerPlugin { | |||
$this->server->on('propFind', [$this, 'handleGetProperties']); | |||
} | |||
private function cacheDirectory(Directory $directory) { | |||
private function cacheDirectory(Directory $directory): void { | |||
$children = $directory->getChildren(); | |||
$ids = []; | |||
@@ -109,14 +104,14 @@ class CommentPropertiesPlugin extends ServerPlugin { | |||
} | |||
// need prefetch ? | |||
if ($node instanceof \OCA\DAV\Connector\Sabre\Directory | |||
if ($node instanceof Directory | |||
&& $propFind->getDepth() !== 0 | |||
&& !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) | |||
) { | |||
$this->cacheDirectory($node); | |||
} | |||
$propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node) { | |||
$propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int { | |||
return $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId()); | |||
}); | |||
@@ -124,19 +119,15 @@ class CommentPropertiesPlugin extends ServerPlugin { | |||
return $this->getCommentsLink($node); | |||
}); | |||
$propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node) { | |||
if (isset($this->cachedUnreadCount[$node->getId()])) { | |||
return $this->cachedUnreadCount[$node->getId()]; | |||
} | |||
return $this->getUnreadCount($node); | |||
$propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node): ?bool { | |||
return $this->cachedUnreadCount[$node->getId()] ?? $this->getUnreadCount($node); | |||
}); | |||
} | |||
/** | |||
* returns a reference to the comments node | |||
* Returns a reference to the comments node | |||
* | |||
* @param Node $node | |||
* @return mixed|string | |||
* @return array|string|null | |||
*/ | |||
public function getCommentsLink(Node $node) { | |||
$href = $this->server->getBaseUri(); | |||
@@ -151,13 +142,10 @@ class CommentPropertiesPlugin extends ServerPlugin { | |||
} | |||
/** | |||
* returns the number of unread comments for the currently logged in user | |||
* Returns the number of unread comments for the currently logged in user | |||
* on the given file or directory node | |||
* | |||
* @param Node $node | |||
* @return Int|null | |||
*/ | |||
public function getUnreadCount(Node $node) { | |||
public function getUnreadCount(Node $node): ?int { | |||
$user = $this->userSession->getUser(); | |||
if (is_null($user)) { | |||
return null; |
@@ -27,6 +27,7 @@ namespace OCA\DAV\Connector\Sabre; | |||
use Sabre\DAV\Exception\NotFound; | |||
use Sabre\HTTP\RequestInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
use Sabre\DAV\Server; | |||
/** | |||
* Copies the "Etag" header to "OC-Etag" after any request. | |||
@@ -34,9 +35,8 @@ use Sabre\HTTP\ResponseInterface; | |||
* or mangle Etag headers. | |||
*/ | |||
class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin { | |||
private Server $server; | |||
/** @var \Sabre\DAV\Server */ | |||
private $server; | |||
/** | |||
* This initializes the plugin. | |||
* |
@@ -54,40 +54,27 @@ use Sabre\DAV\Exception\NotFound; | |||
use Sabre\DAV\Exception\ServiceUnavailable; | |||
use Sabre\DAV\IFile; | |||
use Sabre\DAV\INode; | |||
use OCP\Share\IManager as IShareManager; | |||
class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget { | |||
/** | |||
* Cached directory content | |||
* | |||
* @var \OCP\Files\FileInfo[] | |||
*/ | |||
private $dirContent; | |||
private ?array $dirContent = null; | |||
/** | |||
* Cached quota info | |||
* | |||
* @var array | |||
*/ | |||
private $quotaInfo; | |||
/** | |||
* @var ObjectTree|null | |||
*/ | |||
private $tree; | |||
/** Cached quota info */ | |||
private ?array $quotaInfo = null; | |||
private ?ObjectTree $tree = null; | |||
/** @var array<string, array<int, FileMetadata>> */ | |||
private array $metadata = []; | |||
/** | |||
* Sets up the node, expects a full path name | |||
* | |||
* @param \OC\Files\View $view | |||
* @param \OCP\Files\FileInfo $info | |||
* @param ObjectTree|null $tree | |||
* @param \OCP\Share\IManager $shareManager | |||
*/ | |||
public function __construct(View $view, FileInfo $info, $tree = null, $shareManager = null) { | |||
public function __construct(View $view, FileInfo $info, ?ObjectTree $tree = null, IShareManager $shareManager = null) { | |||
parent::__construct($view, $info, $shareManager); | |||
$this->tree = $tree; | |||
} |
@@ -28,6 +28,7 @@ namespace OCA\DAV\Connector\Sabre; | |||
use Sabre\HTTP\RequestInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
use Sabre\DAV\Server; | |||
/** | |||
* Class DummyGetResponsePlugin is a plugin used to not show a "Not implemented" | |||
@@ -43,8 +44,7 @@ use Sabre\HTTP\ResponseInterface; | |||
* @package OCA\DAV\Connector\Sabre | |||
*/ | |||
class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin { | |||
/** @var \Sabre\DAV\Server */ | |||
protected $server; | |||
protected Server $server; | |||
/** | |||
* @param \Sabre\DAV\Server $server |
@@ -83,16 +83,13 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { | |||
RequestedRangeNotSatisfiable::class => true, | |||
]; | |||
/** @var string */ | |||
private $appName; | |||
private string $appName; | |||
private LoggerInterface $logger; | |||
/** | |||
* @param string $loggerAppName app name to use when logging | |||
* @param LoggerInterface $logger | |||
*/ | |||
public function __construct($loggerAppName, LoggerInterface $logger) { | |||
public function __construct(string $loggerAppName, LoggerInterface $logger) { | |||
$this->appName = $loggerAppName; | |||
$this->logger = $logger; | |||
} | |||
@@ -114,9 +111,8 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { | |||
/** | |||
* Log exception | |||
* | |||
*/ | |||
public function logException(\Throwable $ex) { | |||
public function logException(\Throwable $ex): void { | |||
$exceptionClass = get_class($ex); | |||
if (isset($this->nonFatalExceptions[$exceptionClass]) || | |||
( | |||
@@ -128,11 +124,12 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { | |||
'app' => $this->appName, | |||
'exception' => $ex, | |||
]); | |||
} else { | |||
$this->logger->critical($ex->getMessage(), [ | |||
'app' => $this->appName, | |||
'exception' => $ex, | |||
]); | |||
return; | |||
} | |||
$this->logger->critical($ex->getMessage(), [ | |||
'app' => $this->appName, | |||
'exception' => $ex, | |||
]); | |||
} | |||
} |
@@ -49,6 +49,7 @@ use Sabre\DAV\IFile; | |||
use Sabre\DAV\PropFind; | |||
use Sabre\DAV\PropPatch; | |||
use Sabre\DAV\ServerPlugin; | |||
use Sabre\DAV\Server; | |||
use Sabre\DAV\Tree; | |||
use Sabre\HTTP\RequestInterface; | |||
use Sabre\HTTP\ResponseInterface; | |||
@@ -84,66 +85,28 @@ class FilesPlugin extends ServerPlugin { | |||
public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; | |||
public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; | |||
/** | |||
* Reference to main server object | |||
* | |||
* @var \Sabre\DAV\Server | |||
*/ | |||
private $server; | |||
/** | |||
* @var Tree | |||
*/ | |||
private $tree; | |||
/** | |||
* @var IUserSession | |||
*/ | |||
private $userSession; | |||
/** Reference to main server object */ | |||
private Server $server; | |||
private Tree $tree; | |||
private IUserSession $userSession; | |||
/** | |||
* Whether this is public webdav. | |||
* If true, some returned information will be stripped off. | |||
* | |||
* @var bool | |||
*/ | |||
private $isPublic; | |||
/** | |||
* @var bool | |||
*/ | |||
private $downloadAttachment; | |||
private bool $isPublic; | |||
private bool $downloadAttachment; | |||
private IConfig $config; | |||
private IRequest $request; | |||
private IPreview $previewManager; | |||
/** | |||
* @var IConfig | |||
*/ | |||
private $config; | |||
/** | |||
* @var IRequest | |||
*/ | |||
private $request; | |||
/** | |||
* @var IPreview | |||
*/ | |||
private $previewManager; | |||
/** | |||
* @param Tree $tree | |||
* @param IConfig $config | |||
* @param IRequest $request | |||
* @param IPreview $previewManager | |||
* @param bool $isPublic | |||
* @param bool $downloadAttachment | |||
*/ | |||
public function __construct(Tree $tree, | |||
IConfig $config, | |||
IRequest $request, | |||
IPreview $previewManager, | |||
IUserSession $userSession, | |||
$isPublic = false, | |||
$downloadAttachment = true) { | |||
bool $isPublic = false, | |||
bool $downloadAttachment = true) { | |||
$this->tree = $tree; | |||
$this->config = $config; | |||
$this->request = $request; | |||
@@ -161,10 +124,9 @@ class FilesPlugin extends ServerPlugin { | |||
* | |||
* This method should set up the required event subscriptions. | |||
* | |||
* @param \Sabre\DAV\Server $server | |||
* @return void | |||
*/ | |||
public function initialize(\Sabre\DAV\Server $server) { | |||
public function initialize(Server $server) { | |||
$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; | |||
$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; | |||
$server->protectedProperties[] = self::FILEID_PROPERTYNAME; | |||
@@ -347,7 +309,7 @@ class FilesPlugin extends ServerPlugin { | |||
); | |||
}); | |||
$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { | |||
$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string { | |||
$user = $this->userSession->getUser(); | |||
if ($user === null) { | |||
return null; | |||
@@ -359,11 +321,11 @@ class FilesPlugin extends ServerPlugin { | |||
return json_encode($ocmPermissions); | |||
}); | |||
$propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node) { | |||
$propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string { | |||
return $node->getETag(); | |||
}); | |||
$propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node) { | |||
$propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string { | |||
$owner = $node->getOwner(); | |||
if (!$owner) { | |||
return null; | |||
@@ -371,7 +333,7 @@ class FilesPlugin extends ServerPlugin { | |||
return $owner->getUID(); | |||
} | |||
}); | |||
$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node) { | |||
$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string { | |||
$owner = $node->getOwner(); | |||
if (!$owner) { | |||
return null; | |||
@@ -383,14 +345,14 @@ class FilesPlugin extends ServerPlugin { | |||
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { | |||
return json_encode($this->previewManager->isAvailable($node->getFileInfo())); | |||
}); | |||
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { | |||
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int { | |||
return $node->getSize(); | |||
}); | |||
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { | |||
return $node->getFileInfo()->getMountPoint()->getMountType(); | |||
}); | |||
$propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) { | |||
$propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { | |||
$user = $this->userSession->getUser(); | |||
if ($user === null) { | |||
return null; | |||
@@ -569,10 +531,7 @@ class FilesPlugin extends ServerPlugin { | |||
if (empty($etag)) { | |||
return false; | |||
} | |||
if ($node->setEtag($etag) !== -1) { | |||
return true; | |||
} | |||
return false; | |||
return $node->setEtag($etag) !== -1; | |||
}); | |||
$propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) { | |||
if (empty($time)) { |
@@ -48,25 +48,16 @@ use Sabre\DAV\Auth\Plugin; | |||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |||
class ServerFactory { | |||
/** @var IConfig */ | |||
private $config; | |||
private IConfig $config; | |||
private LoggerInterface $logger; | |||
/** @var IDBConnection */ | |||
private $databaseConnection; | |||
/** @var IUserSession */ | |||
private $userSession; | |||
/** @var IMountManager */ | |||
private $mountManager; | |||
/** @var ITagManager */ | |||
private $tagManager; | |||
/** @var IRequest */ | |||
private $request; | |||
/** @var IPreview */ | |||
private $previewManager; | |||
/** @var EventDispatcherInterface */ | |||
private $eventDispatcher; | |||
/** @var IL10N */ | |||
private $l10n; | |||
private IDBConnection $databaseConnection; | |||
private IUserSession $userSession; | |||
private IMountManager $mountManager; | |||
private ITagManager $tagManager; | |||
private IRequest $request; | |||
private IPreview $previewManager; | |||
private EventDispatcherInterface $eventDispatcher; | |||
private IL10N $l10n; | |||
public function __construct( | |||
IConfig $config, | |||
@@ -93,16 +84,12 @@ class ServerFactory { | |||
} | |||
/** | |||
* @param string $baseUri | |||
* @param string $requestUri | |||
* @param Plugin $authPlugin | |||
* @param callable $viewCallBack callback that should return the view for the dav endpoint | |||
* @return Server | |||
*/ | |||
public function createServer($baseUri, | |||
$requestUri, | |||
public function createServer(string $baseUri, | |||
string $requestUri, | |||
Plugin $authPlugin, | |||
callable $viewCallBack) { | |||
callable $viewCallBack): Server { | |||
// Fire up server | |||
$objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); | |||
$server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
@@ -30,10 +30,14 @@ namespace OCA\DAV\Connector\Sabre; | |||
use OCA\DAV\Connector\Sabre\Node as DavNode; | |||
use OCP\Files\Folder; | |||
use OCP\Files\Node; | |||
use OCP\Files\NotFoundException; | |||
use OCP\IUserSession; | |||
use OCP\Share\IShare; | |||
use OCP\Share\IManager; | |||
use Sabre\DAV\PropFind; | |||
use Sabre\DAV\Tree; | |||
use Sabre\DAV\Server; | |||
/** | |||
* Sabre Plugin to provide share-related properties | |||
@@ -50,36 +54,20 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { | |||
* @var \Sabre\DAV\Server | |||
*/ | |||
private $server; | |||
/** @var \OCP\Share\IManager */ | |||
private $shareManager; | |||
/** @var \Sabre\DAV\Tree */ | |||
private $tree; | |||
/** @var string */ | |||
private $userId; | |||
/** @var \OCP\Files\Folder */ | |||
private $userFolder; | |||
private IManager $shareManager; | |||
private Tree $tree; | |||
private string $userId; | |||
private Folder $userFolder; | |||
/** @var IShare[][] */ | |||
private $cachedShares = []; | |||
private array $cachedShares = []; | |||
/** @var string[] */ | |||
private $cachedFolders = []; | |||
private array $cachedFolders = []; | |||
/** | |||
* @param \Sabre\DAV\Tree $tree tree | |||
* @param IUserSession $userSession user session | |||
* @param \OCP\Files\Folder $userFolder user home folder | |||
* @param \OCP\Share\IManager $shareManager share manager | |||
*/ | |||
public function __construct( | |||
\Sabre\DAV\Tree $tree, | |||
Tree $tree, | |||
IUserSession $userSession, | |||
\OCP\Files\Folder $userFolder, | |||
\OCP\Share\IManager $shareManager | |||
Folder $userFolder, | |||
IManager $shareManager | |||
) { | |||
$this->tree = $tree; | |||
$this->shareManager = $shareManager; | |||
@@ -95,9 +83,9 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { | |||
* | |||
* This method should set up the required event subscriptions. | |||
* | |||
* @param \Sabre\DAV\Server $server | |||
* @return void | |||
*/ | |||
public function initialize(\Sabre\DAV\Server $server) { | |||
public function initialize(Server $server) { | |||
$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; | |||
$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class; | |||
$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; | |||
@@ -108,10 +96,10 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { | |||
} | |||
/** | |||
* @param \OCP\Files\Node $node | |||
* @param Node $node | |||
* @return IShare[] | |||
*/ | |||
private function getShare(\OCP\Files\Node $node): array { | |||
private function getShare(Node $node): array { | |||
$result = []; | |||
$requestedShareTypes = [ | |||
IShare::TYPE_USER, | |||
@@ -209,7 +197,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { | |||
} | |||
} | |||
$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { | |||
$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode): ShareTypeList { | |||
$shares = $this->getShares($sabreNode); | |||
$shareTypes = array_unique(array_map(function (IShare $share) { | |||
@@ -219,7 +207,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { | |||
return new ShareTypeList($shareTypes); | |||
}); | |||
$propFind->handle(self::SHAREES_PROPERTYNAME, function () use ($sabreNode) { | |||
$propFind->handle(self::SHAREES_PROPERTYNAME, function () use ($sabreNode): ShareeList { | |||
$shares = $this->getShares($sabreNode); | |||
return new ShareeList($shares); |
@@ -237,7 +237,7 @@ class Server { | |||
$this->server->addPlugin(new SearchPlugin($lazySearchBackend)); | |||
// wait with registering these until auth is handled and the filesystem is setup | |||
$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { | |||
$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger) { | |||
// custom properties plugin must be the last one | |||
$userSession = \OC::$server->getUserSession(); | |||
$user = $userSession->getUser(); | |||
@@ -306,7 +306,6 @@ class Server { | |||
\OC::$server->getShareManager(), | |||
$view | |||
)); | |||
$logger = \OC::$server->get(LoggerInterface::class); | |||
$this->server->addPlugin( | |||
new BulkUploadPlugin($userFolder, $logger) | |||
); |
@@ -583,11 +583,6 @@ | |||
<code>bool</code> | |||
</InvalidNullableReturnType> | |||
</file> | |||
<file src="apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php"> | |||
<InvalidReturnType occurrences="1"> | |||
<code>bool</code> | |||
</InvalidReturnType> | |||
</file> | |||
<file src="apps/dav/lib/Connector/Sabre/BearerAuth.php"> | |||
<UndefinedInterfaceMethod occurrences="1"> | |||
<code>tryTokenLogin</code> |