From 9e8bbc7c0a1f629e6e968c545c56262fbedf5454 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Thu, 20 Feb 2025 16:35:28 -0500 Subject: [PATCH] enh: add system address book settings in ui Signed-off-by: SebastianKrupinski --- .../composer/composer/autoload_classmap.php | 2 + .../dav/composer/composer/autoload_static.php | 2 + apps/dav/lib/AppInfo/Application.php | 10 +++ .../lib/Listener/DavAdminSettingsListener.php | 65 +++++++++++++++++++ .../Admin/SystemAddressBookSettings.php | 43 ++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 apps/dav/lib/Listener/DavAdminSettingsListener.php create mode 100644 apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 09eb4ba17bd84..7aca345a953ee 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -295,6 +295,7 @@ 'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => $baseDir . '/../lib/Listener/CalendarShareUpdateListener.php', 'OCA\\DAV\\Listener\\CardListener' => $baseDir . '/../lib/Listener/CardListener.php', 'OCA\\DAV\\Listener\\ClearPhotoCacheListener' => $baseDir . '/../lib/Listener/ClearPhotoCacheListener.php', + 'OCA\\DAV\\Listener\\DavAdminSettingsListener' => $baseDir . '/../lib/Listener/DavAdminSettingsListener.php', 'OCA\\DAV\\Listener\\OutOfOfficeListener' => $baseDir . '/../lib/Listener/OutOfOfficeListener.php', 'OCA\\DAV\\Listener\\SubscriptionListener' => $baseDir . '/../lib/Listener/SubscriptionListener.php', 'OCA\\DAV\\Listener\\TrustedServerRemovedListener' => $baseDir . '/../lib/Listener/TrustedServerRemovedListener.php', @@ -357,6 +358,7 @@ 'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php', 'OCA\\DAV\\ServerFactory' => $baseDir . '/../lib/ServerFactory.php', 'OCA\\DAV\\Service\\AbsenceService' => $baseDir . '/../lib/Service/AbsenceService.php', + 'OCA\\DAV\\Settings\\Admin\\SystemAddressBookSettings' => $baseDir . '/../lib/Settings/Admin/SystemAddressBookSettings.php', 'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php', 'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index a2048fcdf0591..b466463058c82 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -310,6 +310,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarShareUpdateListener.php', 'OCA\\DAV\\Listener\\CardListener' => __DIR__ . '/..' . '/../lib/Listener/CardListener.php', 'OCA\\DAV\\Listener\\ClearPhotoCacheListener' => __DIR__ . '/..' . '/../lib/Listener/ClearPhotoCacheListener.php', + 'OCA\\DAV\\Listener\\DavAdminSettingsListener' => __DIR__ . '/..' . '/../lib/Listener/DavAdminSettingsListener.php', 'OCA\\DAV\\Listener\\OutOfOfficeListener' => __DIR__ . '/..' . '/../lib/Listener/OutOfOfficeListener.php', 'OCA\\DAV\\Listener\\SubscriptionListener' => __DIR__ . '/..' . '/../lib/Listener/SubscriptionListener.php', 'OCA\\DAV\\Listener\\TrustedServerRemovedListener' => __DIR__ . '/..' . '/../lib/Listener/TrustedServerRemovedListener.php', @@ -372,6 +373,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php', 'OCA\\DAV\\ServerFactory' => __DIR__ . '/..' . '/../lib/ServerFactory.php', 'OCA\\DAV\\Service\\AbsenceService' => __DIR__ . '/..' . '/../lib/Service/AbsenceService.php', + 'OCA\\DAV\\Settings\\Admin\\SystemAddressBookSettings' => __DIR__ . '/..' . '/../lib/Settings/Admin/SystemAddressBookSettings.php', 'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php', 'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php', diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index 4db58b0f137fc..60a51678128a0 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -57,6 +57,7 @@ use OCA\DAV\Listener\CalendarShareUpdateListener; use OCA\DAV\Listener\CardListener; use OCA\DAV\Listener\ClearPhotoCacheListener; +use OCA\DAV\Listener\DavAdminSettingsListener; use OCA\DAV\Listener\OutOfOfficeListener; use OCA\DAV\Listener\SubscriptionListener; use OCA\DAV\Listener\TrustedServerRemovedListener; @@ -65,6 +66,7 @@ use OCA\DAV\Search\ContactsSearchProvider; use OCA\DAV\Search\EventsSearchProvider; use OCA\DAV\Search\TasksSearchProvider; +use OCA\DAV\Settings\Admin\SystemAddressBookSettings; use OCA\DAV\SetupChecks\NeedsSystemAddressBookSync; use OCA\DAV\SetupChecks\WebdavEndpoint; use OCA\DAV\UserMigration\CalendarMigrator; @@ -85,6 +87,8 @@ use OCP\Files\AppData\IAppDataFactory; use OCP\IUserSession; use OCP\Server; +use OCP\Settings\Events\DeclarativeSettingsGetValueEvent; +use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\BeforeUserIdUnassignedEvent; use OCP\User\Events\OutOfOfficeChangedEvent; @@ -212,6 +216,12 @@ public function register(IRegistrationContext $context): void { $context->registerSetupCheck(NeedsSystemAddressBookSync::class); $context->registerSetupCheck(WebdavEndpoint::class); + + // register admin settings form and listener(s) + $context->registerDeclarativeSettings(SystemAddressBookSettings::class); + $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DavAdminSettingsListener::class); + $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DavAdminSettingsListener::class); + } public function boot(IBootContext $context): void { diff --git a/apps/dav/lib/Listener/DavAdminSettingsListener.php b/apps/dav/lib/Listener/DavAdminSettingsListener.php new file mode 100644 index 0000000000000..c59c2df157527 --- /dev/null +++ b/apps/dav/lib/Listener/DavAdminSettingsListener.php @@ -0,0 +1,65 @@ + */ +class DavAdminSettingsListener implements IEventListener { + + public function __construct( + private IAppConfig $config, + ) { + } + + public function handle(Event $event): void { + + /** @var DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent $event */ + if ($event->getApp() !== Application::APP_ID) { + return; + } + + if ($event->getFormId() !== 'dav-admin-system-address-book') { + return; + } + + if ($event instanceof DeclarativeSettingsGetValueEvent) { + $this->handleGetValue($event); + return; + } + + if ($event instanceof DeclarativeSettingsSetValueEvent) { + $this->handleSetValue($event); + return; + } + + } + + private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void { + + if ($event->getFieldId() === 'system_addressbook_enabled') { + $event->setValue((int)$this->config->getValueBool('dav', 'system_addressbook_exposed', true)); + } + + } + + private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void { + + if ($event->getFieldId() === 'system_addressbook_enabled') { + $this->config->setValueBool('dav', 'system_addressbook_exposed', (bool)$event->getValue()); + $event->stopPropagation(); + } + + } + +} diff --git a/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php b/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php new file mode 100644 index 0000000000000..2f7b9f8fcc9d7 --- /dev/null +++ b/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php @@ -0,0 +1,43 @@ + 'dav-admin-system-address-book', + 'priority' => 10, + 'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN, + 'section_id' => 'groupware', + 'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL, + 'title' => $this->l->t('System Address Book'), + 'description' => $this->l->t('The system address book contains contact information for all users in your instance.'), + + 'fields' => [ + [ + 'id' => 'system_addressbook_enabled', + 'title' => $this->l->t('Enable System Address Book'), + 'type' => DeclarativeSettingsTypes::CHECKBOX, + 'default' => false, + 'options' => [], + ], + ], + ]; + } + +}