Skip to content

Commit

Permalink
Merge pull request #31943 from nextcloud/dav-cleanup
Browse files Browse the repository at this point in the history
Cleanup dav
  • Loading branch information
CarlSchwan authored May 17, 2022
2 parents a4f23b1 + f7be761 commit 07c9bf1
Show file tree
Hide file tree
Showing 40 changed files with 222 additions and 687 deletions.
2 changes: 1 addition & 1 deletion apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

// Add plugins
$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
$server->addPlugin(new \Sabre\CalDAV\Plugin());

$server->addPlugin(new LegacyDAVACL());
Expand Down
5 changes: 4 additions & 1 deletion apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -48,7 +51,7 @@

$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(),
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/appinfo/v1/webdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -39,7 +41,7 @@

$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(),
Expand Down
1 change: 0 additions & 1 deletion apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
'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',
Expand Down
1 change: 0 additions & 1 deletion apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ public function __construct(IDBConnection $db,
$this->timeFactory = $timeFactory;
}

/**
* @param $arguments
*/
public function run($arguments) {
$offset = (int) $arguments['offset'];
$stopAt = (int) $arguments['stopAt'];
public function run($argument) {
$offset = (int) $argument['offset'];
$stopAt = (int) $argument['stopAt'];

$this->logger->info('Building calendar reminder index (' . $offset .'/' . $stopAt . ')');

Expand Down
3 changes: 1 addition & 2 deletions apps/dav/lib/BackgroundJob/EventReminderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public function __construct(ITimeFactory $time,
}

/**
* @param $arg
* @throws \OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException
* @throws \OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException
* @throws \OC\User\NoUserException
*/
public function run($arg):void {
public function run($argument):void {
if ($this->config->getAppValue('dav', 'sendEventReminders', 'yes') !== 'yes') {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ public function __construct(ITimeFactory $time,
$this->config = $config;
}

/**
* @param array $arguments
*/
public function run($arguments) {
$userId = $arguments['userId'];
$purgeBeforeGenerating = $arguments['purgeBeforeGenerating'] ?? false;
public function run($argument) {
$userId = $argument['userId'];
$purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false;

// make sure admin didn't change his mind
$isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
Expand Down
10 changes: 4 additions & 6 deletions apps/dav/lib/BackgroundJob/UploadCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\Files\Node;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;

class UploadCleanup extends TimedJob {

/** @var IRootFolder */
private $rootFolder;

/** @var IJobList */
private $jobList;
private IRootFolder $rootFolder;
private IJobList $jobList;

public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) {
parent::__construct($time);
Expand Down Expand Up @@ -71,6 +68,7 @@ protected function run($argument) {
return;
}

/** @var File[] $files */
$files = $uploadFolder->getDirectoryListing();

// Remove if all files have an mtime of more than a day
Expand Down
48 changes: 9 additions & 39 deletions apps/dav/lib/CalDAV/BirthdayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,15 @@
*/
class BirthdayService {
public const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';

/** @var GroupPrincipalBackend */
private $principalBackend;

/** @var CalDavBackend */
private $calDavBackEnd;

/** @var CardDavBackend */
private $cardDavBackEnd;

/** @var IConfig */
private $config;

/** @var IDBConnection */
private $dbConnection;

/** @var IL10N */
private $l10n;
private GroupPrincipalBackend $principalBackend;
private CalDavBackend $calDavBackEnd;
private CardDavBackend $cardDavBackEnd;
private IConfig $config;
private IDBConnection $dbConnection;
private IL10N $l10n;

/**
* BirthdayService constructor.
*
* @param CalDavBackend $calDavBackEnd
* @param CardDavBackend $cardDavBackEnd
* @param GroupPrincipalBackend $principalBackend
* @param IConfig $config
* @param IDBConnection $dbConnection
* @param IL10N $l10n
*/
public function __construct(CalDavBackend $calDavBackEnd,
CardDavBackend $cardDavBackEnd,
Expand All @@ -96,14 +77,9 @@ public function __construct(CalDavBackend $calDavBackEnd,
$this->l10n = $l10n;
}

/**
* @param int $addressBookId
* @param string $cardUri
* @param string $cardData
*/
public function onCardChanged(int $addressBookId,
string $cardUri,
string $cardData) {
string $cardData): void {
if (!$this->isGloballyEnabled()) {
return;
}
Expand All @@ -129,12 +105,8 @@ public function onCardChanged(int $addressBookId,
}
}

/**
* @param int $addressBookId
* @param string $cardUri
*/
public function onCardDeleted(int $addressBookId,
string $cardUri) {
string $cardUri): void {
if (!$this->isGloballyEnabled()) {
return;
}
Expand All @@ -156,11 +128,9 @@ public function onCardDeleted(int $addressBookId,
}

/**
* @param string $principal
* @return array|null
* @throws \Sabre\DAV\Exception\BadRequest
*/
public function ensureCalendarExists(string $principal):?array {
public function ensureCalendarExists(string $principal): ?array {
$calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
if (!is_null($calendar)) {
return $calendar;
Expand Down
13 changes: 7 additions & 6 deletions apps/dav/lib/CalDAV/CachedSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode;
use Sabre\DAV\PropPatch;

/**
Expand All @@ -51,7 +52,7 @@ public function getPrincipalURI():string {
/**
* @return array
*/
public function getACL():array {
public function getACL() {
return [
[
'privilege' => '{DAV:}read',
Expand Down Expand Up @@ -79,7 +80,7 @@ public function getACL():array {
/**
* @return array
*/
public function getChildACL():array {
public function getChildACL() {
return [
[
'privilege' => '{DAV:}read',
Expand Down Expand Up @@ -139,9 +140,9 @@ public function getChild($name) {
}

/**
* @return array
* @return INode[]
*/
public function getChildren():array {
public function getChildren(): array {
$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

$children = [];
Expand Down Expand Up @@ -169,8 +170,8 @@ public function getMultipleChildren(array $paths):array {

/**
* @param string $name
* @param null $calendarData
* @return null|string|void
* @param null|resource|string $calendarData
* @return null|string
* @throws MethodNotAllowed
*/
public function createFile($name, $calendarData = null) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/CachedSubscriptionObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function get() {

/**
* @param resource|string $calendarData
* @return string|void
* @return string
* @throws MethodNotAllowed
*/
public function put($calendarData) {
Expand Down
5 changes: 1 addition & 4 deletions apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
* @package OCA\DAV\CalDAV\ICSExportPlugin
*/
class ICSExportPlugin extends \Sabre\CalDAV\ICSExportPlugin {

/** @var IConfig */
private $config;

private IConfig $config;
private LoggerInterface $logger;

/** @var string */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(bool $public = true) {
));

// 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,
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/CalDAV/Publishing/PublishPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function propFind(PropFind $propFind, INode $node) {
$canPublish = (!$node->isSubscription() && $node->canWrite());

if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') {
$canShare &= ($node->getOwner() === $node->getPrincipalURI());
$canPublish &= ($node->getOwner() === $node->getPrincipalURI());
$canShare = $canShare && ($node->getOwner() === $node->getPrincipalURI());
$canPublish = $canPublish && ($node->getOwner() === $node->getPrincipalURI());
}

return new AllowedSharingModes($canShare, $canPublish);
Expand Down
Loading

0 comments on commit 07c9bf1

Please sign in to comment.