Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: Register system_addressbook_exposed in lexicon
Signed-off-by: Louis Chmn <[email protected]>
  • Loading branch information
artonge committed Oct 10, 2025
commit e976a1323fc3aa23d82a8e055e16387bd6288f0d
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
'OCA\\DAV\\Comments\\EntityCollection' => $baseDir . '/../lib/Comments/EntityCollection.php',
'OCA\\DAV\\Comments\\EntityTypeCollection' => $baseDir . '/../lib/Comments/EntityTypeCollection.php',
'OCA\\DAV\\Comments\\RootCollection' => $baseDir . '/../lib/Comments/RootCollection.php',
'OCA\\DAV\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
'OCA\\DAV\\Connector\\LegacyDAVACL' => $baseDir . '/../lib/Connector/LegacyDAVACL.php',
'OCA\\DAV\\Connector\\LegacyPublicAuth' => $baseDir . '/../lib/Connector/LegacyPublicAuth.php',
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => $baseDir . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Comments\\EntityCollection' => __DIR__ . '/..' . '/../lib/Comments/EntityCollection.php',
'OCA\\DAV\\Comments\\EntityTypeCollection' => __DIR__ . '/..' . '/../lib/Comments/EntityTypeCollection.php',
'OCA\\DAV\\Comments\\RootCollection' => __DIR__ . '/..' . '/../lib/Comments/RootCollection.php',
'OCA\\DAV\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
'OCA\\DAV\\Connector\\LegacyDAVACL' => __DIR__ . '/..' . '/../lib/Connector/LegacyDAVACL.php',
'OCA\\DAV\\Connector\\LegacyPublicAuth' => __DIR__ . '/..' . '/../lib/Connector/LegacyPublicAuth.php',
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCA\DAV\CardDAV\ContactsManager;
use OCA\DAV\CardDAV\Notification\Notifier as NotifierCardDAV;
use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Events\AddressBookCreatedEvent;
use OCA\DAV\Events\AddressBookDeletedEvent;
use OCA\DAV\Events\AddressBookShareUpdatedEvent;
Expand Down Expand Up @@ -228,6 +229,8 @@ public function register(IRegistrationContext $context): void {
$context->registerDeclarativeSettings(SystemAddressBookSettings::class);
$context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DavAdminSettingsListener::class);
$context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DavAdminSettingsListener::class);

$context->registerConfigLexicon(ConfigLexicon::class);
}

public function boot(IBootContext $context): void {
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/lib/CardDAV/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
namespace OCA\DAV\CardDAV;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\Db\PropertyMapper;
use OCP\Contacts\IManager;
use OCP\IAppConfig;
Expand Down Expand Up @@ -45,7 +47,7 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG
* @param IURLGenerator $urlGenerator
*/
public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) {
$systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true);
$systemAddressBookExposed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED);
if (!$systemAddressBookExposed) {
return;
}
Expand Down
25 changes: 12 additions & 13 deletions apps/dav/lib/CardDAV/UserAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
*/
namespace OCA\DAV\CardDAV;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
use OCA\DAV\ConfigLexicon;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\QueryException;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Server;
use OCP\Util;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Sabre\CardDAV\Backend;
Expand All @@ -30,11 +34,9 @@
use function array_map;

class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
/** @var IL10N */
protected $l10n;

/** @var IConfig */
protected $config;
protected IL10N $l10n;
protected IConfig $config;
protected IAppConfig $appConfig;

public function __construct(
Backend\BackendInterface $carddavBackend,
Expand All @@ -44,6 +46,10 @@ public function __construct(
private ?IGroupManager $groupManager,
) {
parent::__construct($carddavBackend, $principalUri);

$this->l10n = Util::getL10N('dav');
$this->config = Server::get(IConfig::class);
$this->appConfig = Server::get(IAppConfig::class);
}

/**
Expand All @@ -52,19 +58,12 @@ public function __construct(
* @return IAddressBook[]
*/
public function getChildren() {
if ($this->l10n === null) {
$this->l10n = \OC::$server->getL10N('dav');
}
if ($this->config === null) {
$this->config = Server::get(IConfig::class);
}

/** @var string|array $principal */
$principal = $this->principalUri;
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
// add the system address book
$systemAddressBook = null;
$systemAddressBookExposed = $this->config->getAppValue('dav', 'system_addressbook_exposed', 'yes') === 'yes';
$systemAddressBookExposed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED);
if ($systemAddressBookExposed && is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) {
$systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system');
if ($systemAddressBook !== null) {
Expand Down
45 changes: 45 additions & 0 deletions apps/dav/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV;

use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for files_sharing.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const SYSTEM_ADDRESSBOOK_EXPOSED = 'system_addressbook_exposed';

public function getStrictness(): Strictness {
return Strictness::NOTICE;
}

public function getAppConfigs(): array {
return [
new Entry(
self::SYSTEM_ADDRESSBOOK_EXPOSED,
ValueType::BOOL,
defaultRaw: true,
definition: 'Whether to not expose the system address book to users',
lazy: true,
),
];
}

public function getUserConfigs(): array {
return [];
}
}
9 changes: 3 additions & 6 deletions apps/dav/lib/Listener/DavAdminSettingsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\DAV\Listener;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IAppConfig;
Expand Down Expand Up @@ -46,20 +47,16 @@ public function handle(Event $event): void {
}

private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void {

if ($event->getFieldId() === 'system_addressbook_enabled') {
$event->setValue((int)$this->config->getValueBool('dav', 'system_addressbook_exposed', true));
$event->setValue((int)$this->config->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED));
}

}

private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void {

if ($event->getFieldId() === 'system_addressbook_enabled') {
$this->config->setValueBool('dav', 'system_addressbook_exposed', (bool)$event->getValue());
$this->config->setValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED, (bool)$event->getValue());
$event->stopPropagation();
}

}

}
5 changes: 3 additions & 2 deletions apps/dav/lib/Migration/DisableSystemAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\DAV\Migration;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function getName() {
*/
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) {
if ($this->appConfig->hasAppKey(ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED) === true) {
$output->info('Skipping repair step system address book exposed was previously set');
return;
}
Expand All @@ -50,7 +51,7 @@ public function run(IOutput $output) {
$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);
$this->appConfig->setAppValueBool(ConfigLexicon::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) {
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/lib/SetupChecks/SystemAddressBookSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\DAV\SetupChecks;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\IUserManager;
Expand All @@ -33,7 +34,7 @@ public function getCategory(): string {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\DAV\Tests\SetupChecks;

use OCA\DAV\AppInfo\Application;
use OCA\DAV\ConfigLexicon;
use OCA\DAV\SetupChecks\SystemAddressBookSize;
use OCP\IAppConfig;
use OCP\IL10N;
Expand All @@ -30,7 +31,7 @@ protected function setUp(): void {

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

$check = new SystemAddressBookSize($this->appConfig, $this->userManager, $this->l10n);
Expand Down
4 changes: 0 additions & 4 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,6 @@
</DeprecatedMethod>
</file>
<file src="apps/dav/lib/CardDAV/UserAddressBooks.php">
<DeprecatedMethod>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getL10N]]></code>
</DeprecatedMethod>
<InvalidArgument>
<code><![CDATA[$this->principalUri]]></code>
<code><![CDATA[$this->principalUri]]></code>
Expand Down
Loading