diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php index feca586d94638..2b7b1e23478a2 100644 --- a/apps/dav/lib/CardDAV/ContactsManager.php +++ b/apps/dav/lib/CardDAV/ContactsManager.php @@ -8,11 +8,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; use OCP\IL10N; use OCP\IURLGenerator; @@ -27,7 +24,6 @@ public function __construct( private CardDavBackend $backend, private IL10N $l10n, private PropertyMapper $propertyMapper, - private IAppConfig $appConfig, ) { } @@ -48,11 +44,6 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG * @param IURLGenerator $urlGenerator */ public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) { - $systemAddressBookExposed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::SYSTEM_ADDRESSBOOK_EXPOSED); - if (!$systemAddressBookExposed) { - return; - } - $addressBooks = $this->backend->getAddressBooksForUser('principals/system/system'); $this->register($cm, $addressBooks, $urlGenerator, $userId); } diff --git a/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php b/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php index 9b96314238bae..500bb17e1442c 100644 --- a/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php +++ b/apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php @@ -28,12 +28,12 @@ public function getSchema(): array { '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.'), + 'description' => $this->l->t('The system address book contains contact information for all users in your instance. The system address book is required for the searching and auto-completion of users.'), 'fields' => [ [ 'id' => 'system_addressbook_enabled', - 'title' => $this->l->t('Enable System Address Book'), + 'title' => $this->l->t('Enable System Address Book in DAV clients'), 'type' => DeclarativeSettingsTypes::CHECKBOX, 'default' => false, 'options' => [], diff --git a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php index 00cb16aada4a6..6f6dfc4c56018 100644 --- a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php +++ b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php @@ -13,31 +13,66 @@ use OCA\DAV\CardDAV\ContactsManager; use OCA\DAV\Db\PropertyMapper; use OCP\Contacts\IManager; -use OCP\IAppConfig; +use OCP\IAddressBook; use OCP\IL10N; use OCP\IURLGenerator; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class ContactsManagerTest extends TestCase { - public function test(): void { - /** @var IManager&MockObject $cm */ - $cm = $this->createMock(IManager::class); - $cm->expects($this->exactly(1))->method('registerAddressBook'); - /** @var IURLGenerator&MockObject $urlGenerator */ - $urlGenerator = $this->createMock(IURLGenerator::class); - /** @var CardDavBackend&MockObject $backEnd */ - $backEnd = $this->createMock(CardDavBackend::class); - $backEnd->method('getAddressBooksForUser')->willReturn([ - ['{DAV:}displayname' => 'Test address book', 'uri' => 'default'], - ]); - $propertyMapper = $this->createMock(PropertyMapper::class); - /** @var IAppConfig&MockObject $appConfig */ - $appConfig = $this->createMock(IAppConfig::class); - - /** @var IL10N&MockObject $l */ - $l = $this->createMock(IL10N::class); - $app = new ContactsManager($backEnd, $l, $propertyMapper, $appConfig); - $app->setupContactsProvider($cm, 'user01', $urlGenerator); + private IManager&MockObject $contactsManager; + private IURLGenerator&MockObject $urlGenerator; + private CardDavBackend&MockObject $backend; + private PropertyMapper&MockObject $propertyMapper; + private IL10N&MockObject $l10n; + private ContactsManager $manager; + + protected function setUp(): void { + parent::setUp(); + + $this->contactsManager = $this->createMock(IManager::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->backend = $this->createMock(CardDavBackend::class); + $this->propertyMapper = $this->createMock(PropertyMapper::class); + $this->l10n = $this->createMock(IL10N::class); + + $this->backend->method('getAddressBooksForUser') + ->willReturnCallback(static fn (string $principalUri): array => match ($principalUri) { + 'principals/users/user01' => [ + ['id' => 1, 'uri' => 'default', 'principaluri' => $principalUri, '{DAV:}displayname' => 'Test address book'], + ], + 'principals/system/system' => [ + ['id' => 2, 'uri' => 'system', 'principaluri' => $principalUri, '{DAV:}displayname' => 'System address book'], + ], + default => [], + }); + + $this->manager = new ContactsManager($this->backend, $this->l10n, $this->propertyMapper); + } + + public function testSetupContactsProvider(): void { + $registered = []; + $this->contactsManager->expects($this->exactly(2)) + ->method('registerAddressBook') + ->willReturnCallback(function (IAddressBook $addressBook) use (&$registered): void { + $registered[] = $addressBook->getUri(); + }); + + $this->manager->setupContactsProvider($this->contactsManager, 'user01', $this->urlGenerator); + + $this->assertEquals(['default', 'system'], $registered); + } + + public function testSetupSystemContactsProvider(): void { + $registered = []; + $this->contactsManager->expects($this->exactly(1)) + ->method('registerAddressBook') + ->willReturnCallback(function (IAddressBook $addressBook) use (&$registered): void { + $registered[] = $addressBook->getUri(); + }); + + $this->manager->setupSystemContactsProvider($this->contactsManager, 'user01', $this->urlGenerator); + + $this->assertEquals(['system'], $registered); } } diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index c8ef1143574b6..da6426abeba07 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -29,5 +29,6 @@ protected function resetAppConfigs(): void { $this->deleteServerConfig('bruteforcesettings', 'apply_allowlist_to_ratelimit'); $this->deleteServerConfig('core', 'shareapi_exclude_groups'); $this->deleteServerConfig('core', 'shareapi_exclude_groups_list'); + $this->deleteServerConfig('dav', 'system_addressbook_exposed'); } } diff --git a/build/integration/features/contacts-menu.feature b/build/integration/features/contacts-menu.feature index 077a33d14a13a..f250121863586 100644 --- a/build/integration/features/contacts-menu.feature +++ b/build/integration/features/contacts-menu.feature @@ -359,18 +359,20 @@ Feature: contacts-menu # Disabled because it regularly fails on drone: # Then the list of searched contacts has "0" contacts - Scenario: users cannot list other users from the system address book + # The example contact of the personal address book is listed next to "user0" of the system address book + Scenario: users can list other users from the system address book Given user "user0" exists And user "user1" exists - And invoking occ with "config:app:set dav system_addressbook_exposed --value false" And Logging in using web as "user1" And searching for contacts matching with "" - Then the list of searched contacts has "1" contacts - And invoking occ with "config:app:delete dav system_addressbook_exposed" + Then the list of searched contacts has "2" contacts - Scenario: users can list other users from the system address book + # Exposing the system address book is only about DAV clients, user searching and + # auto-completion keep working when it is disabled + Scenario: users can list other users from the system address book when it is not exposed to DAV clients Given user "user0" exists And user "user1" exists + And invoking occ with "config:app:set dav system_addressbook_exposed --value false" And Logging in using web as "user1" And searching for contacts matching with "" Then the list of searched contacts has "2" contacts