diff options
author | Georg Ehrke <developer@georgehrke.com> | 2020-08-04 07:57:07 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2020-08-05 09:04:41 +0200 |
commit | b0c5457c422888f87b76f2b67f05917aed02a775 (patch) | |
tree | eb423d096287fb63d9a8a939c025ff6290b74393 /apps/dav | |
parent | 1cf9f4281795610bfaf74af9e3f3f1c3c544c08c (diff) | |
download | nextcloud-server-b0c5457c422888f87b76f2b67f05917aed02a775.tar.gz nextcloud-server-b0c5457c422888f87b76f2b67f05917aed02a775.zip |
IAddressBook: add isShared and isSystemAddressBook
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 29 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/AddressBookImplTest.php | 59 |
2 files changed, 82 insertions, 6 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 6ec3fed8276..02dc7c5d015 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -281,12 +281,7 @@ class AddressBookImpl implements IAddressBook { } } - if ( - $this->addressBookInfo['principaluri'] === 'principals/system/system' && ( - $this->addressBookInfo['uri'] === 'system' || - $this->addressBookInfo['{DAV:}displayname'] === $this->urlGenerator->getBaseUrl() - ) - ) { + if ($this->isSystemAddressBook()) { $result['isLocalSystemBook'] = true; } return $result; @@ -309,4 +304,26 @@ class AddressBookImpl implements IAddressBook { return null; } + + /** + * @inheritDoc + */ + public function isShared(): bool { + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { + return false; + } + + return $this->addressBookInfo['principaluri'] + !== $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; + } + + /** + * @inheritDoc + */ + public function isSystemAddressBook(): bool { + return $this->addressBookInfo['principaluri'] === 'principals/system/system' && ( + $this->addressBookInfo['uri'] === 'system' || + $this->addressBookInfo['{DAV:}displayname'] === $this->urlGenerator->getBaseUrl() + ); + } } diff --git a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php index cc7e50e9374..242106fbcc9 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php @@ -447,4 +447,63 @@ class AddressBookImplTest extends TestCase { 'isLocalSystemBook' => true, ], $array); } + + public function testIsSystemAddressBook(): void { + $addressBookInfo = [ + '{http://owncloud.org/ns}owner-principal' => 'principals/system/system', + 'principaluri' => 'principals/system/system', + '{DAV:}displayname' => 'display name', + 'id' => 666, + 'uri' => 'system', + ]; + + $addressBookImpl = new AddressBookImpl( + $this->addressBook, + $addressBookInfo, + $this->backend, + $this->urlGenerator + ); + + $this->assertTrue($addressBookImpl->isSystemAddressBook()); + } + + public function testIsShared(): void { + $addressBookInfo = [ + '{http://owncloud.org/ns}owner-principal' => 'user1', + '{DAV:}displayname' => 'Test address book', + 'principaluri' => 'user2', + 'id' => 666, + 'uri' => 'default', + ]; + + $addressBookImpl = new AddressBookImpl( + $this->addressBook, + $addressBookInfo, + $this->backend, + $this->urlGenerator + ); + + $this->assertFalse($addressBookImpl->isSystemAddressBook()); + $this->assertTrue($addressBookImpl->isShared()); + } + + public function testIsNotShared(): void { + $addressBookInfo = [ + '{http://owncloud.org/ns}owner-principal' => 'user1', + '{DAV:}displayname' => 'Test address book', + 'principaluri' => 'user1', + 'id' => 666, + 'uri' => 'default', + ]; + + $addressBookImpl = new AddressBookImpl( + $this->addressBook, + $addressBookInfo, + $this->backend, + $this->urlGenerator + ); + + $this->assertFalse($addressBookImpl->isSystemAddressBook()); + $this->assertFalse($addressBookImpl->isShared()); + } } |