diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php index b35137c902d50..85f96bac146dd 100644 --- a/apps/dav/lib/CardDAV/ContactsManager.php +++ b/apps/dav/lib/CardDAV/ContactsManager.php @@ -9,6 +9,7 @@ use OCA\DAV\Db\PropertyMapper; use OCP\Contacts\IManager; +use OCP\IAppConfig; use OCP\IL10N; use OCP\IURLGenerator; @@ -23,6 +24,7 @@ public function __construct( private CardDavBackend $backend, private IL10N $l10n, private PropertyMapper $propertyMapper, + private IAppConfig $appConfig, ) { } @@ -43,6 +45,11 @@ public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlG * @param IURLGenerator $urlGenerator */ public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) { + $systemAddressBookExposed = $this->appConfig->getValueBool('dav', 'system_addressbook_exposed', true); + if (!$systemAddressBookExposed) { + return; + } + $addressBooks = $this->backend->getAddressBooksForUser('principals/system/system'); $this->register($cm, $addressBooks, $urlGenerator, $userId); } diff --git a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php index bdd826f671b6f..90caeed666880 100644 --- a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php +++ b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php @@ -12,6 +12,7 @@ use OCA\DAV\CardDAV\ContactsManager; use OCA\DAV\Db\PropertyMapper; use OCP\Contacts\IManager; +use OCP\IAppConfig; use OCP\IL10N; use OCP\IURLGenerator; use PHPUnit\Framework\MockObject\MockObject; @@ -21,7 +22,8 @@ class ContactsManagerTest extends TestCase { public function test(): void { /** @var IManager&MockObject $cm */ $cm = $this->createMock(IManager::class); - $cm->expects($this->exactly(2))->method('registerAddressBook'); + $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); @@ -29,9 +31,12 @@ public function test(): void { ['{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); + $app = new ContactsManager($backEnd, $l, $propertyMapper, $appConfig); $app->setupContactsProvider($cm, 'user01', $urlGenerator); } } diff --git a/build/integration/features/contacts-menu.feature b/build/integration/features/contacts-menu.feature index 772c0e5405cfb..a3a9e0f666740 100644 --- a/build/integration/features/contacts-menu.feature +++ b/build/integration/features/contacts-menu.feature @@ -192,3 +192,19 @@ Feature: contacts-menu And searching for contacts matching with "test" # 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 + 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" + + Scenario: users can list other users from the system address book + Given user "user0" exists + And user "user1" exists + And Logging in using web as "user1" + And searching for contacts matching with "" + Then the list of searched contacts has "2" contacts