Skip to content

Commit

Permalink
IAddressBook: add isShared and isSystemAddressBook
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke committed Aug 5, 2020
1 parent 1cf9f42 commit b0c5457
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
29 changes: 23 additions & 6 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,7 @@ protected function vCard2Array($uri, VCard $vCard, $withTypes = false) {
}
}

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;
Expand All @@ -309,4 +304,26 @@ protected function getTypeFromProperty(Property $property) {

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()
);
}
}
59 changes: 59 additions & 0 deletions apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,63 @@ public function testVCard2ArrayWithTypes() {
'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());
}
}
15 changes: 15 additions & 0 deletions lib/public/IAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,20 @@ public function getPermissions();
* @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;
}
}

0 comments on commit b0c5457

Please sign in to comment.