Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions apps/dav/lib/CardDAV/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +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;
use OCP\IL10N;
use OCP\IURLGenerator;

Expand All @@ -26,7 +23,6 @@ public function __construct(
private CardDavBackend $backend,
private IL10N $l10n,
private PropertyMapper $propertyMapper,
private IAppConfig $appConfig,
) {
}

Expand All @@ -47,11 +43,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);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/Settings/Admin/SystemAddressBookSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,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' => [],
Expand Down
75 changes: 55 additions & 20 deletions apps/dav/tests/unit/CardDAV/ContactsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,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);
}
}
1 change: 1 addition & 0 deletions build/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
12 changes: 7 additions & 5 deletions build/integration/features/contacts-menu.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading