aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorHamza Mahjoubi <hamzamahjoubi221@gmail.com>2025-03-10 20:35:27 +0100
committerHamza Mahjoubi <hamzamahjoubi221@gmail.com>2025-03-17 11:56:34 +0100
commitc9d9abd46eb5c2c071829c8afc7accaaf2ba89c0 (patch)
tree1c715ee83d474a69383287bf1ecebd07586951a5 /apps
parentac4d805cb9d494200948cef75e84888066d665f4 (diff)
downloadnextcloud-server-fix/noid/contactsmenu-ab-enabled.tar.gz
nextcloud-server-fix/noid/contactsmenu-ab-enabled.zip
fix(cardav): only show useres from enabled addressBooks in contacts menufix/noid/contactsmenu-ab-enabled
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/AppInfo/Application.php5
-rw-r--r--apps/dav/lib/CardDAV/AddressBookImpl.php28
-rw-r--r--apps/dav/lib/CardDAV/ContactsManager.php18
-rw-r--r--apps/dav/tests/unit/CardDAV/AddressBookImplTest.php31
-rw-r--r--apps/dav/tests/unit/CardDAV/ContactsManagerTest.php4
5 files changed, 70 insertions, 16 deletions
diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php
index fc79eaf5e18..1c105cffca5 100644
--- a/apps/dav/lib/AppInfo/Application.php
+++ b/apps/dav/lib/AppInfo/Application.php
@@ -279,12 +279,11 @@ class Application extends App implements IBootstrap {
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
}
- private function setupSystemContactsProvider(IContactsManager $contactsManager,
- IAppContainer $container): void {
+ private function setupSystemContactsProvider(IContactsManager $contactsManager, IAppContainer $container): void {
/** @var ContactsManager $cm */
$cm = $container->query(ContactsManager::class);
$urlGenerator = $container->getServer()->getURLGenerator();
- $cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
+ $cm->setupSystemContactsProvider($contactsManager, null, $urlGenerator);
}
public function registerCalendarManager(ICalendarManager $calendarManager,
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php
index e37281e92eb..8657460d0c6 100644
--- a/apps/dav/lib/CardDAV/AddressBookImpl.php
+++ b/apps/dav/lib/CardDAV/AddressBookImpl.php
@@ -7,15 +7,16 @@
*/
namespace OCA\DAV\CardDAV;
+use OCA\DAV\Db\PropertyMapper;
use OCP\Constants;
-use OCP\IAddressBook;
+use OCP\IAddressBookEnabled;
use OCP\IURLGenerator;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property;
use Sabre\VObject\Reader;
use Sabre\VObject\UUIDUtil;
-class AddressBookImpl implements IAddressBook {
+class AddressBookImpl implements IAddressBookEnabled {
/**
* AddressBookImpl constructor.
@@ -30,6 +31,8 @@ class AddressBookImpl implements IAddressBook {
private array $addressBookInfo,
private CardDavBackend $backend,
private IURLGenerator $urlGenerator,
+ private PropertyMapper $propertyMapper,
+ private ?string $userId,
) {
}
@@ -308,4 +311,25 @@ class AddressBookImpl implements IAddressBook {
$this->addressBookInfo['{DAV:}displayname'] === $this->urlGenerator->getBaseUrl()
);
}
+
+ public function isEnabled(): bool {
+ if (!$this->userId) {
+ return true;
+ }
+
+ if ($this->isSystemAddressBook()) {
+ $user = $this->userId ;
+ $uri = 'z-server-generated--system';
+ } else {
+ $user = str_replace('principals/users/', '', $this->addressBookInfo['principaluri']);
+ $uri = $this->addressBookInfo['uri'];
+ }
+
+ $path = 'addressbooks/users/' . $user . '/' . $uri;
+ $properties = $this->propertyMapper->findPropertyByPathAndName($user, $path, '{http://owncloud.org/ns}enabled');
+ if (count($properties) > 0) {
+ return (bool)$properties[0]->getPropertyvalue();
+ }
+ return true;
+ }
}
diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php
index 39e4e6aa117..b35137c902d 100644
--- a/apps/dav/lib/CardDAV/ContactsManager.php
+++ b/apps/dav/lib/CardDAV/ContactsManager.php
@@ -7,6 +7,7 @@
*/
namespace OCA\DAV\CardDAV;
+use OCA\DAV\Db\PropertyMapper;
use OCP\Contacts\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -21,6 +22,7 @@ class ContactsManager {
public function __construct(
private CardDavBackend $backend,
private IL10N $l10n,
+ private PropertyMapper $propertyMapper,
) {
}
@@ -31,25 +33,27 @@ class ContactsManager {
*/
public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
$addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
- $this->register($cm, $addressBooks, $urlGenerator);
- $this->setupSystemContactsProvider($cm, $urlGenerator);
+ $this->register($cm, $addressBooks, $urlGenerator, $userId);
+ $this->setupSystemContactsProvider($cm, $userId, $urlGenerator);
}
/**
* @param IManager $cm
+ * @param ?string $userId
* @param IURLGenerator $urlGenerator
*/
- public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) {
+ public function setupSystemContactsProvider(IManager $cm, ?string $userId, IURLGenerator $urlGenerator) {
$addressBooks = $this->backend->getAddressBooksForUser('principals/system/system');
- $this->register($cm, $addressBooks, $urlGenerator);
+ $this->register($cm, $addressBooks, $urlGenerator, $userId);
}
/**
* @param IManager $cm
* @param $addressBooks
* @param IURLGenerator $urlGenerator
+ * @param ?string $userId
*/
- private function register(IManager $cm, $addressBooks, $urlGenerator) {
+ private function register(IManager $cm, $addressBooks, $urlGenerator, ?string $userId) {
foreach ($addressBooks as $addressBookInfo) {
$addressBook = new AddressBook($this->backend, $addressBookInfo, $this->l10n);
$cm->registerAddressBook(
@@ -57,7 +61,9 @@ class ContactsManager {
$addressBook,
$addressBookInfo,
$this->backend,
- $urlGenerator
+ $urlGenerator,
+ $this->propertyMapper,
+ $userId,
)
);
}
diff --git a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
index dff368b923c..a8bfc1b41fd 100644
--- a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
+++ b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
@@ -10,6 +10,7 @@ namespace OCA\DAV\Tests\unit\CardDAV;
use OCA\DAV\CardDAV\AddressBook;
use OCA\DAV\CardDAV\AddressBookImpl;
use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\Db\PropertyMapper;
use OCP\IURLGenerator;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
@@ -32,6 +33,9 @@ class AddressBookImplTest extends TestCase {
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject */
private $backend;
+ /** @var PropertyMapper | \PHPUnit\Framework\MockObject\MockObject */
+ private $propertyMapper;
+
/** @var VCard | \PHPUnit\Framework\MockObject\MockObject */
private $vCard;
@@ -50,12 +54,15 @@ class AddressBookImplTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->vCard = $this->createMock(VCard::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->propertyMapper = $this->createMock(PropertyMapper::class);
$this->addressBookImpl = new AddressBookImpl(
$this->addressBook,
$this->addressBookInfo,
$this->backend,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->propertyMapper,
+ null
);
}
@@ -78,6 +85,8 @@ class AddressBookImplTest extends TestCase {
$this->addressBookInfo,
$this->backend,
$this->urlGenerator,
+ $this->propertyMapper,
+ null
]
)
->setMethods(['vCard2Array', 'readCard'])
@@ -124,6 +133,8 @@ class AddressBookImplTest extends TestCase {
$this->addressBookInfo,
$this->backend,
$this->urlGenerator,
+ $this->propertyMapper,
+ null
]
)
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard'])
@@ -174,6 +185,8 @@ class AddressBookImplTest extends TestCase {
$this->addressBookInfo,
$this->backend,
$this->urlGenerator,
+ $this->propertyMapper,
+ null
]
)
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
@@ -211,6 +224,8 @@ class AddressBookImplTest extends TestCase {
$this->addressBookInfo,
$this->backend,
$this->urlGenerator,
+ $this->propertyMapper,
+ null
]
)
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
@@ -292,6 +307,8 @@ class AddressBookImplTest extends TestCase {
$this->addressBookInfo,
$this->backend,
$this->urlGenerator,
+ $this->propertyMapper,
+ null
]
)
->setMethods(['getUid'])
@@ -488,7 +505,9 @@ class AddressBookImplTest extends TestCase {
$this->addressBook,
$addressBookInfo,
$this->backend,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->propertyMapper,
+ null
);
$this->assertTrue($addressBookImpl->isSystemAddressBook());
@@ -507,7 +526,9 @@ class AddressBookImplTest extends TestCase {
$this->addressBook,
$addressBookInfo,
$this->backend,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->propertyMapper,
+ 'user2'
);
$this->assertFalse($addressBookImpl->isSystemAddressBook());
@@ -527,7 +548,9 @@ class AddressBookImplTest extends TestCase {
$this->addressBook,
$addressBookInfo,
$this->backend,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->propertyMapper,
+ 'user2'
);
$this->assertFalse($addressBookImpl->isSystemAddressBook());
diff --git a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php
index 6b1abb2718d..80f1f2a4445 100644
--- a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php
+++ b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php
@@ -9,6 +9,7 @@ namespace OCA\DAV\Tests\unit\CardDAV;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
+use OCA\DAV\Db\PropertyMapper;
use OCP\Contacts\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -25,9 +26,10 @@ class ContactsManagerTest extends TestCase {
$backEnd->method('getAddressBooksForUser')->willReturn([
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
]);
+ $propertyMapper = $this->createMock(PropertyMapper::class);
$l = $this->createMock(IL10N::class);
- $app = new ContactsManager($backEnd, $l);
+ $app = new ContactsManager($backEnd, $l, $propertyMapper);
$app->setupContactsProvider($cm, 'user01', $urlGenerator);
}
}