Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/dav/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<step>OCA\DAV\Migration\CalDAVRemoveEmptyValue</step>
<step>OCA\DAV\Migration\BuildCalendarSearchIndex</step>
<step>OCA\DAV\Migration\BuildSocialSearchIndex</step>
<step>OCA\DAV\Migration\DisableSystemAddressBook</step>
<step>OCA\DAV\Migration\RefreshWebcalJobRegistrar</step>
<step>OCA\DAV\Migration\RegisterBuildReminderIndexBackgroundJob</step>
<step>OCA\DAV\Migration\RegisterUpdateCalendarResourcesRoomBackgroundJob</step>
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
'OCA\\DAV\\CardDAV\\Integration\\ExternalAddressBook' => $baseDir . '/../lib/CardDAV/Integration/ExternalAddressBook.php',
'OCA\\DAV\\CardDAV\\Integration\\IAddressBookProvider' => $baseDir . '/../lib/CardDAV/Integration/IAddressBookProvider.php',
'OCA\\DAV\\CardDAV\\MultiGetExportPlugin' => $baseDir . '/../lib/CardDAV/MultiGetExportPlugin.php',
'OCA\\DAV\\CardDAV\\Notification\\Notifier' => $baseDir . '/../lib/CardDAV/Notification/Notifier.php',
'OCA\\DAV\\CardDAV\\PhotoCache' => $baseDir . '/../lib/CardDAV/PhotoCache.php',
'OCA\\DAV\\CardDAV\\Plugin' => $baseDir . '/../lib/CardDAV/Plugin.php',
'OCA\\DAV\\CardDAV\\Security\\CardDavRateLimitingPlugin' => $baseDir . '/../lib/CardDAV/Security/CardDavRateLimitingPlugin.php',
Expand Down Expand Up @@ -345,6 +346,7 @@
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php',
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php',
'OCA\\DAV\\Migration\\DisableSystemAddressBook' => $baseDir . '/../lib/Migration/DisableSystemAddressBook.php',
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
'OCA\\DAV\\Migration\\RegenerateBirthdayCalendars' => $baseDir . '/../lib/Migration/RegenerateBirthdayCalendars.php',
Expand Down Expand Up @@ -407,6 +409,7 @@
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
'OCA\\DAV\\Settings\\ExampleContentSettings' => $baseDir . '/../lib/Settings/ExampleContentSettings.php',
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\DAV\\SetupChecks\\SystemAddressBookSize' => $baseDir . '/../lib/SetupChecks/SystemAddressBookSize.php',
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => $baseDir . '/../lib/SetupChecks/WebdavEndpoint.php',
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
'OCA\\DAV\\Storage\\PublicShareWrapper' => $baseDir . '/../lib/Storage/PublicShareWrapper.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\CardDAV\\Integration\\ExternalAddressBook' => __DIR__ . '/..' . '/../lib/CardDAV/Integration/ExternalAddressBook.php',
'OCA\\DAV\\CardDAV\\Integration\\IAddressBookProvider' => __DIR__ . '/..' . '/../lib/CardDAV/Integration/IAddressBookProvider.php',
'OCA\\DAV\\CardDAV\\MultiGetExportPlugin' => __DIR__ . '/..' . '/../lib/CardDAV/MultiGetExportPlugin.php',
'OCA\\DAV\\CardDAV\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/CardDAV/Notification/Notifier.php',
'OCA\\DAV\\CardDAV\\PhotoCache' => __DIR__ . '/..' . '/../lib/CardDAV/PhotoCache.php',
'OCA\\DAV\\CardDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CardDAV/Plugin.php',
'OCA\\DAV\\CardDAV\\Security\\CardDavRateLimitingPlugin' => __DIR__ . '/..' . '/../lib/CardDAV/Security/CardDavRateLimitingPlugin.php',
Expand Down Expand Up @@ -360,6 +361,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php',
'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php',
'OCA\\DAV\\Migration\\DisableSystemAddressBook' => __DIR__ . '/..' . '/../lib/Migration/DisableSystemAddressBook.php',
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
'OCA\\DAV\\Migration\\RegenerateBirthdayCalendars' => __DIR__ . '/..' . '/../lib/Migration/RegenerateBirthdayCalendars.php',
Expand Down Expand Up @@ -422,6 +424,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
'OCA\\DAV\\Settings\\ExampleContentSettings' => __DIR__ . '/..' . '/../lib/Settings/ExampleContentSettings.php',
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\DAV\\SetupChecks\\SystemAddressBookSize' => __DIR__ . '/..' . '/../lib/SetupChecks/SystemAddressBookSize.php',
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => __DIR__ . '/..' . '/../lib/SetupChecks/WebdavEndpoint.php',
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
'OCA\\DAV\\Storage\\PublicShareWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicShareWrapper.php',
Expand Down
8 changes: 6 additions & 2 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\Notifier;
use OCA\DAV\CalDAV\Reminder\Notifier as NotifierCalDAV;
use OCA\DAV\Capabilities;
use OCA\DAV\CardDAV\ContactsManager;
use OCA\DAV\CardDAV\Notification\Notifier as NotifierCardDAV;
use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\Events\AddressBookCreatedEvent;
use OCA\DAV\Events\AddressBookDeletedEvent;
Expand Down Expand Up @@ -64,6 +65,7 @@
use OCA\DAV\Search\TasksSearchProvider;
use OCA\DAV\Settings\Admin\SystemAddressBookSettings;
use OCA\DAV\SetupChecks\NeedsSystemAddressBookSync;
use OCA\DAV\SetupChecks\SystemAddressBookSize;
use OCA\DAV\SetupChecks\WebdavEndpoint;
use OCA\DAV\UserMigration\CalendarMigrator;
use OCA\DAV\UserMigration\ContactsMigrator;
Expand Down Expand Up @@ -209,7 +211,8 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarFederationNotificationListener::class);
$context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarFederationNotificationListener::class);

$context->registerNotifierService(Notifier::class);
$context->registerNotifierService(NotifierCalDAV::class);
$context->registerNotifierService(NotifierCardDAV::class);

$context->registerCalendarProvider(CalendarProvider::class);
$context->registerCalendarProvider(CachedSubscriptionProvider::class);
Expand All @@ -218,6 +221,7 @@ public function register(IRegistrationContext $context): void {
$context->registerUserMigrator(ContactsMigrator::class);

$context->registerSetupCheck(NeedsSystemAddressBookSync::class);
$context->registerSetupCheck(SystemAddressBookSize::class);
$context->registerSetupCheck(WebdavEndpoint::class);

// register admin settings form and listener(s)
Expand Down
69 changes: 69 additions & 0 deletions apps/dav/lib/CardDAV/Notification/Notifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CardDAV\Notification;

use InvalidArgumentException;
use OCA\DAV\AppInfo\Application;
use OCP\IL10N;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;

class Notifier implements INotifier {

public function __construct(
protected IFactory $l10nFactory,
) {
}

/**
* @inheritDoc
*/
public function getID(): string {
return Application::APP_ID;
}

/**
* @inheritDoc
*/
public function getName(): string {
return $this->l10nFactory->get(Application::APP_ID)->t('Contacts');
}

/**
* @inheritDoc
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== Application::APP_ID) {
throw new InvalidArgumentException();
}

$l = $this->l10nFactory->get(Application::APP_ID, $languageCode);

return match ($notification->getSubject()) {
'SystemAddressBookDisabled' => $this->parseSystemAddressBookDisabled($notification, $l),
default => throw new UnknownNotificationException()
};
}

/**
* Generates a notification for the system address book being disabled.
*/
protected function parseSystemAddressBookDisabled(INotification $notification, IL10N $l): INotification {
$command = 'occ config:app:set dav system_addressbook_exposed --value="yes"';
$notification->setParsedSubject(
$l->t('System address book disabled')
)->setParsedMessage(
$l->t('The system contacts address book has been automatically disabled during upgrade. This means that the address book will no longer be available to users in the contacts app or other clients. The system contacts address book was disabled because the amount of contacts in the address book exceeded the maximum recommended number of contacts. This limit is set to prevent performance issues. You can re-enable the system address book with the following command {command}', ['command' => $command])
);
return $notification;
}

}
65 changes: 65 additions & 0 deletions apps/dav/lib/Migration/DisableSystemAddressBook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Migration;

use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\Notification\IManager;
use OCP\ServerVersion;

class DisableSystemAddressBook implements IRepairStep {

public function __construct(
private readonly ServerVersion $serverVersion,
private readonly IAppConfig $appConfig,
private readonly IUserManager $userManager,
private readonly IGroupManager $groupManager,
private readonly IManager $notificationManager,
) {
}

/**
* @inheritdoc
*/
public function getName() {
return 'Disable system address book';
}

/**
* @inheritdoc
*/
public function run(IOutput $output) {
// If the system address book exposure was previously set skip the repair step
if ($this->appConfig->hasAppKey('system_addressbook_exposed') === true) {
$output->info('Skipping repair step system address book exposed was previously set');
return;
}
// We use count seen because getting a user count from the backend can be very slow
$limit = $this->appConfig->getAppValueInt('system_addressbook_limit', 5000);
if ($this->userManager->countSeenUsers() <= $limit) {
$output->info("Skipping repair step system address book has less then the threshold $limit of contacts no need to disable");
return;
}
$this->appConfig->setAppValueBool('system_addressbook_exposed', false);
$output->warning("System address book disabled because it has more then the threshold of $limit contacts this can be re-enabled later");
// Notify all admin users about the system address book being disabled
foreach ($this->groupManager->get('admin')->getUsers() as $user) {
$notification = $this->notificationManager->createNotification();
$notification->setApp(Application::APP_ID)
->setUser($user->getUID())
->setDateTime(new \DateTime())
->setSubject('SystemSystemAddressBookDisabled', []);
$this->notificationManager->notify($notification);
}
}
}
50 changes: 50 additions & 0 deletions apps/dav/lib/SetupChecks/SystemAddressBookSize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\SetupChecks;

use OCA\DAV\AppInfo\Application;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class SystemAddressBookSize implements ISetupCheck {
public function __construct(
private IAppConfig $appConfig,
private IUserManager $userManager,
private IL10N $l10n,
) {
}

public function getName(): string {
return $this->l10n->t('DAV system address book size');
}

public function getCategory(): string {
return 'dav';
}

public function run(): SetupResult {
if (!$this->appConfig->getValueBool(Application::APP_ID, 'system_addressbook_exposed', true)) {
return SetupResult::success($this->l10n->t('The system address book is disabled'));
}

// We use count seen because getting a user count from the backend can be very slow
$count = $this->userManager->countSeenUsers();
$limit = $this->appConfig->getValueInt(Application::APP_ID, 'system_addressbook_limit', 5000);

if ($count > $limit) {
return SetupResult::warning($this->l10n->t('The system address book is enabled, but contains more than the configured limit of %d contacts', [$limit]));
} else {
return SetupResult::success($this->l10n->t('The system address book is enabled and contains less than the configured limit of %d contacts', [$limit]));
}
}
}
69 changes: 69 additions & 0 deletions apps/dav/tests/unit/SetupChecks/SystemAddressBookSizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\Tests\SetupChecks;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\SetupChecks\SystemAddressBookSize;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\IUserManager;
use PHPUnit\Framework\TestCase;

class SystemAddressBookSizeTest extends TestCase {
private $appConfig;
private $userManager;
private $l10n;

protected function setUp(): void {
$this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10n->method('t')->willReturnCallback(fn ($text, $parameters = []) => vsprintf($text, $parameters));
}

public function testSystemAddressBookDisabled() {
$this->appConfig->method('getValueBool')
->with(Application::APP_ID, 'system_addressbook_exposed', true)
->willReturn(false);

$check = new SystemAddressBookSize($this->appConfig, $this->userManager, $this->l10n);
$result = $check->run();
$this->assertEquals('success', $result->getSeverity());
$this->assertStringContainsString('disabled', $result->getDescription());
}

public function testSystemAddressBookOverLimit() {
$this->appConfig->method('getValueBool')
->willReturn(true);
$this->userManager->method('countSeenUsers')
->willReturn(6000);
$this->appConfig->method('getValueInt')
->willReturn(5000);

$check = new SystemAddressBookSize($this->appConfig, $this->userManager, $this->l10n);
$result = $check->run();
$this->assertEquals('warning', $result->getSeverity());
$this->assertStringContainsString('more than the configured limit', $result->getDescription());
}

public function testSystemAddressBookUnderLimit() {
$this->appConfig->method('getValueBool')
->willReturn(true);
$this->userManager->method('countSeenUsers')
->willReturn(1000);
$this->appConfig->method('getValueInt')
->willReturn(5000);

$check = new SystemAddressBookSize($this->appConfig, $this->userManager, $this->l10n);
$result = $check->run();
$this->assertEquals('success', $result->getSeverity());
$this->assertStringContainsString('less than the configured limit', $result->getDescription());
}
}
Loading