Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>pull/50933/head
parent
4efd119df7
commit
9b0302f7ac
@ -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\Listener; |
||||
|
||||
use OCA\DAV\AppInfo\Application; |
||||
use OCP\EventDispatcher\Event; |
||||
use OCP\EventDispatcher\IEventListener; |
||||
use OCP\IAppConfig; |
||||
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent; |
||||
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; |
||||
|
||||
/** @template-implements IEventListener<DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent> */ |
||||
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(); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
/** |
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
namespace OCA\DAV\Settings\Admin; |
||||
|
||||
use OCP\IL10N; |
||||
use OCP\Settings\DeclarativeSettingsTypes; |
||||
use OCP\Settings\IDeclarativeSettingsForm; |
||||
|
||||
class SystemAddressBookSettings implements IDeclarativeSettingsForm { |
||||
|
||||
public function __construct( |
||||
private IL10N $l, |
||||
) { |
||||
} |
||||
|
||||
public function getSchema(): array { |
||||
return [ |
||||
'id' => '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' => [], |
||||
], |
||||
], |
||||
]; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue