]> source.dussan.org Git - nextcloud-server.git/commitdiff
IAddressBook: add isShared and isSystemAddressBook 22098/head
authorGeorg Ehrke <developer@georgehrke.com>
Tue, 4 Aug 2020 05:57:07 +0000 (07:57 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Wed, 5 Aug 2020 07:04:41 +0000 (09:04 +0200)
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
apps/dav/lib/CardDAV/AddressBookImpl.php
apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
lib/public/IAddressBook.php

index 6ec3fed8276a1af2f556d1917284ca0aa6786997..02dc7c5d0159f399ac6d31e41c2072865d91c0a0 100644 (file)
@@ -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()
+               );
+       }
 }
index cc7e50e937437c350054d6bf4a6fec6bded5ec9f..242106fbcc99e1cb25f29d329e4257a36bc10806 100644 (file)
@@ -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());
+       }
 }
index b2c9a103c2cf55808fe2af6b97666b52a4a4cc16..ed66af4aa18146a2a76466a10c808c008ea5e984 100644 (file)
@@ -107,5 +107,20 @@ namespace OCP {
                 * @since 5.0.0
                 */
                public function delete($id);
+
+               /**
+                * Returns true if this address-book is not owned by the current user,
+                * but shared with them.
+                *
+                * @return bool
+                * @since 20.0.0
+                */
+               public function isShared(): bool;
+
+               /**
+                * @return bool
+                * @since 20.0.0
+                */
+               public function isSystemAddressBook(): bool;
        }
 }