mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
chore: Register system_addressbook_exposed in lexicon
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
parent
d14c96b26d
commit
e976a1323f
11 changed files with 75 additions and 28 deletions
|
|
@ -206,6 +206,7 @@ return array(
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ 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\ConfigLexicon;
|
||||
use OCA\DAV\Events\AddressBookCreatedEvent;
|
||||
use OCA\DAV\Events\AddressBookDeletedEvent;
|
||||
use OCA\DAV\Events\AddressBookShareUpdatedEvent;
|
||||
|
|
@ -228,6 +229,8 @@ class Application extends App implements IBootstrap {
|
|||
$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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -45,7 +47,7 @@ class ContactsManager {
|
|||
* @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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,14 @@ declare(strict_types=1);
|
|||
*/
|
||||
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;
|
||||
|
|
@ -21,6 +24,7 @@ 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;
|
||||
|
|
@ -30,11 +34,9 @@ use Sabre\DAV\MkCol;
|
|||
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,
|
||||
|
|
@ -44,6 +46,10 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
|
|||
private ?IGroupManager $groupManager,
|
||||
) {
|
||||
parent::__construct($carddavBackend, $principalUri);
|
||||
|
||||
$this->l10n = Util::getL10N('dav');
|
||||
$this->config = Server::get(IConfig::class);
|
||||
$this->appConfig = Server::get(IAppConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,19 +58,12 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
|
|||
* @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) {
|
||||
|
|
|
|||
45
apps/dav/lib/ConfigLexicon.php
Normal file
45
apps/dav/lib/ConfigLexicon.php
Normal file
|
|
@ -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 [];
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ declare(strict_types=1);
|
|||
namespace OCA\DAV\Listener;
|
||||
|
||||
use OCA\DAV\AppInfo\Application;
|
||||
use OCA\DAV\ConfigLexicon;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\IAppConfig;
|
||||
|
|
@ -46,20 +47,16 @@ class DavAdminSettingsListener implements IEventListener {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
namespace OCA\DAV\Migration;
|
||||
|
||||
use OCA\DAV\AppInfo\Application;
|
||||
use OCA\DAV\ConfigLexicon;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -40,7 +41,7 @@ class DisableSystemAddressBook implements IRepairStep {
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ class DisableSystemAddressBook implements IRepairStep {
|
|||
$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) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace OCA\DAV\SetupChecks;
|
||||
|
||||
use OCA\DAV\AppInfo\Application;
|
||||
use OCA\DAV\ConfigLexicon;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -33,7 +34,7 @@ class SystemAddressBookSize implements ISetupCheck {
|
|||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
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;
|
||||
|
|
@ -30,7 +31,7 @@ class SystemAddressBookSizeTest extends TestCase {
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue