Skip to content

Commit 68ba9a7

Browse files
committed
chore: Register system_addressbook_exposed in lexicon
Signed-off-by: Louis Chemineau <[email protected]>
1 parent 3b0b17b commit 68ba9a7

File tree

10 files changed

+75
-24
lines changed

10 files changed

+75
-24
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
'OCA\\DAV\\Comments\\EntityCollection' => $baseDir . '/../lib/Comments/EntityCollection.php',
207207
'OCA\\DAV\\Comments\\EntityTypeCollection' => $baseDir . '/../lib/Comments/EntityTypeCollection.php',
208208
'OCA\\DAV\\Comments\\RootCollection' => $baseDir . '/../lib/Comments/RootCollection.php',
209+
'OCA\\DAV\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
209210
'OCA\\DAV\\Connector\\LegacyDAVACL' => $baseDir . '/../lib/Connector/LegacyDAVACL.php',
210211
'OCA\\DAV\\Connector\\LegacyPublicAuth' => $baseDir . '/../lib/Connector/LegacyPublicAuth.php',
211212
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => $baseDir . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class ComposerStaticInitDAV
221221
'OCA\\DAV\\Comments\\EntityCollection' => __DIR__ . '/..' . '/../lib/Comments/EntityCollection.php',
222222
'OCA\\DAV\\Comments\\EntityTypeCollection' => __DIR__ . '/..' . '/../lib/Comments/EntityTypeCollection.php',
223223
'OCA\\DAV\\Comments\\RootCollection' => __DIR__ . '/..' . '/../lib/Comments/RootCollection.php',
224+
'OCA\\DAV\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
224225
'OCA\\DAV\\Connector\\LegacyDAVACL' => __DIR__ . '/..' . '/../lib/Connector/LegacyDAVACL.php',
225226
'OCA\\DAV\\Connector\\LegacyPublicAuth' => __DIR__ . '/..' . '/../lib/Connector/LegacyPublicAuth.php',
226227
'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php',

apps/dav/lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCA\DAV\CardDAV\ContactsManager;
2424
use OCA\DAV\CardDAV\Notification\Notifier as NotifierCardDAV;
2525
use OCA\DAV\CardDAV\SyncService;
26+
use OCA\DAV\ConfigLexicon;
2627
use OCA\DAV\Events\AddressBookCreatedEvent;
2728
use OCA\DAV\Events\AddressBookDeletedEvent;
2829
use OCA\DAV\Events\AddressBookShareUpdatedEvent;
@@ -228,6 +229,8 @@ public function register(IRegistrationContext $context): void {
228229
$context->registerDeclarativeSettings(SystemAddressBookSettings::class);
229230
$context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DavAdminSettingsListener::class);
230231
$context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DavAdminSettingsListener::class);
232+
233+
$context->registerConfigLexicon(ConfigLexicon::class);
231234
}
232235

233236
public function boot(IBootContext $context): void {

apps/dav/lib/CardDAV/ContactsManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
namespace OCA\DAV\CardDAV;
99

10+
use OCA\DAV\AppInfo\Application;
11+
use OCA\DAV\ConfigLexicon;
1012
use OCA\DAV\Db\PropertyMapper;
1113
use OCP\Contacts\IManager;
1214
use OCP\IAppConfig;
@@ -45,7 +47,7 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG
4547
* @param IURLGenerator $urlGenerator
4648
*/
4749
public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) {
48-
$systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true);
50+
$systemAddressBookExposed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED);
4951
if (!$systemAddressBookExposed) {
5052
return;
5153
}

apps/dav/lib/CardDAV/UserAddressBooks.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
*/
1010
namespace OCA\DAV\CardDAV;
1111

12+
use OCA\DAV\AppInfo\Application;
1213
use OCA\DAV\AppInfo\PluginManager;
1314
use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
1415
use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
16+
use OCA\DAV\ConfigLexicon;
1517
use OCA\Federation\TrustedServers;
1618
use OCP\AppFramework\QueryException;
19+
use OCP\IAppConfig;
1720
use OCP\IConfig;
1821
use OCP\IGroupManager;
1922
use OCP\IL10N;
2023
use OCP\IRequest;
2124
use OCP\IUser;
2225
use OCP\IUserSession;
2326
use OCP\Server;
27+
use OCP\Util;
2428
use Psr\Container\ContainerExceptionInterface;
2529
use Psr\Container\NotFoundExceptionInterface;
2630
use Sabre\CardDAV\Backend;
@@ -30,11 +34,9 @@
3034
use function array_map;
3135

3236
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
33-
/** @var IL10N */
34-
protected $l10n;
35-
36-
/** @var IConfig */
37-
protected $config;
37+
protected IL10N $l10n;
38+
protected IConfig $config;
39+
protected IAppConfig $appConfig;
3840

3941
public function __construct(
4042
Backend\BackendInterface $carddavBackend,
@@ -44,6 +46,10 @@ public function __construct(
4446
private ?IGroupManager $groupManager,
4547
) {
4648
parent::__construct($carddavBackend, $principalUri);
49+
50+
$this->l10n = Util::getL10N('dav');
51+
$this->config = Server::get(IConfig::class);
52+
$this->appConfig = Server::get(IAppConfig::class);
4753
}
4854

4955
/**
@@ -52,19 +58,12 @@ public function __construct(
5258
* @return IAddressBook[]
5359
*/
5460
public function getChildren() {
55-
if ($this->l10n === null) {
56-
$this->l10n = \OC::$server->getL10N('dav');
57-
}
58-
if ($this->config === null) {
59-
$this->config = Server::get(IConfig::class);
60-
}
61-
6261
/** @var string|array $principal */
6362
$principal = $this->principalUri;
6463
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
6564
// add the system address book
6665
$systemAddressBook = null;
67-
$systemAddressBookExposed = $this->config->getAppValue('dav', 'system_addressbook_exposed', 'yes') === 'yes';
66+
$systemAddressBookExposed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED);
6867
if ($systemAddressBookExposed && is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) {
6968
$systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system');
7069
if ($systemAddressBook !== null) {

apps/dav/lib/ConfigLexicon.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV;
10+
11+
use OCP\Config\Lexicon\Entry;
12+
use OCP\Config\Lexicon\ILexicon;
13+
use OCP\Config\Lexicon\Strictness;
14+
use OCP\Config\ValueType;
15+
16+
/**
17+
* Config Lexicon for files_sharing.
18+
*
19+
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
20+
*
21+
* {@see ILexicon}
22+
*/
23+
class ConfigLexicon implements ILexicon {
24+
public const SYSTEM_ADDRESSBOOK_EXPOSED = 'system_addressbook_exposed';
25+
26+
public function getStrictness(): Strictness {
27+
return Strictness::NOTICE;
28+
}
29+
30+
public function getAppConfigs(): array {
31+
return [
32+
new Entry(
33+
self::SYSTEM_ADDRESSBOOK_EXPOSED,
34+
ValueType::BOOL,
35+
defaultRaw: true,
36+
definition: 'Whether to not expose the system address book to users',
37+
lazy: true,
38+
),
39+
];
40+
}
41+
42+
public function getUserConfigs(): array {
43+
return [];
44+
}
45+
}

apps/dav/lib/Listener/DavAdminSettingsListener.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\DAV\Listener;
99

1010
use OCA\DAV\AppInfo\Application;
11+
use OCA\DAV\ConfigLexicon;
1112
use OCP\EventDispatcher\Event;
1213
use OCP\EventDispatcher\IEventListener;
1314
use OCP\IAppConfig;
@@ -46,20 +47,16 @@ public function handle(Event $event): void {
4647
}
4748

4849
private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void {
49-
5050
if ($event->getFieldId() === 'system_addressbook_enabled') {
51-
$event->setValue((int)$this->config->getValueBool('dav', 'system_addressbook_exposed', true));
51+
$event->setValue((int)$this->config->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED));
5252
}
53-
5453
}
5554

5655
private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void {
57-
5856
if ($event->getFieldId() === 'system_addressbook_enabled') {
59-
$this->config->setValueBool('dav', 'system_addressbook_exposed', (bool)$event->getValue());
57+
$this->config->setValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED, (bool)$event->getValue());
6058
$event->stopPropagation();
6159
}
62-
6360
}
6461

6562
}

apps/dav/lib/Migration/DisableSystemAddressBook.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\DAV\Migration;
1010

1111
use OCA\DAV\AppInfo\Application;
12+
use OCA\DAV\ConfigLexicon;
1213
use OCP\AppFramework\Services\IAppConfig;
1314
use OCP\IGroupManager;
1415
use OCP\IUserManager;
@@ -40,7 +41,7 @@ public function getName() {
4041
*/
4142
public function run(IOutput $output) {
4243
// If the system address book exposure was previously set skip the repair step
43-
if ($this->appConfig->hasAppKey('system_addressbook_exposed') === true) {
44+
if ($this->appConfig->hasAppKey(ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED) === true) {
4445
$output->info('Skipping repair step system address book exposed was previously set');
4546
return;
4647
}
@@ -50,7 +51,7 @@ public function run(IOutput $output) {
5051
$output->info("Skipping repair step system address book has less then the threshold $limit of contacts no need to disable");
5152
return;
5253
}
53-
$this->appConfig->setAppValueBool('system_addressbook_exposed', false);
54+
$this->appConfig->setAppValueBool(ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED, false);
5455
$output->warning("System address book disabled because it has more then the threshold of $limit contacts this can be re-enabled later");
5556
// Notify all admin users about the system address book being disabled
5657
foreach ($this->groupManager->get('admin')->getUsers() as $user) {

apps/dav/lib/SetupChecks/SystemAddressBookSize.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\DAV\SetupChecks;
1111

1212
use OCA\DAV\AppInfo\Application;
13+
use OCA\DAV\ConfigLexicon;
1314
use OCP\IAppConfig;
1415
use OCP\IL10N;
1516
use OCP\IUserManager;
@@ -33,7 +34,7 @@ public function getCategory(): string {
3334
}
3435

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

apps/dav/tests/unit/SetupChecks/SystemAddressBookSizeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\DAV\Tests\SetupChecks;
1111

1212
use OCA\DAV\AppInfo\Application;
13+
use OCA\DAV\ConfigLexicon;
1314
use OCA\DAV\SetupChecks\SystemAddressBookSize;
1415
use OCP\IAppConfig;
1516
use OCP\IL10N;
@@ -30,7 +31,7 @@ protected function setUp(): void {
3031

3132
public function testSystemAddressBookDisabled() {
3233
$this->appConfig->method('getValueBool')
33-
->with(Application::APP_ID, 'system_addressbook_exposed', true)
34+
->with(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED)
3435
->willReturn(false);
3536

3637
$check = new SystemAddressBookSize($this->appConfig, $this->userManager, $this->l10n);

0 commit comments

Comments
 (0)