Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 27 additions & 0 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,33 @@ function getAddressBooksForUser($principalUri) {
return array_values($addressBooks);
}

function getUsersOwnAddressBooks($principalUri) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put a explicit "public" in front of the function. Seems like this file has a wired mixture here but I would like to keep it consistent with the other code.

Maybe it would also make sense to write a unit test for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already some unit tests for it in testDeleteCalendar. Is it enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you want bigger test, i'm sorry but I don't have the necessary knowledge to do correct ones here.
I'm too unfamiliar with the whole phpunit section here and don't have enough time to read to assimilate it :(

$principalUriOriginal = $principalUri;
$principalUri = $this->convertPrincipal($principalUri, true);
$query = $this->db->getQueryBuilder();
$query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
->from('addressbooks')
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));

$addressBooks = [];

$result = $query->execute();
while($row = $result->fetch()) {
$addressBooks[$row['id']] = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'{DAV:}displayname' => $row['displayname'],
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];
}
$result->closeCursor();

return array_values($addressBooks);
}

private function getUserDisplayName($uid) {
if (!isset($this->userDisplayNames[$uid])) {
$user = $this->userManager->get($uid);
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function preDeleteUser($params) {
$uid = $params['uid'];
$this->usersToDelete[$uid] = $this->userManager->get($uid);
$this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid);
$this->addressBooksToDelete = $this->cardDav->getAddressBooksForUser('principals/users/' . $uid);
$this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid);
}

public function postDeleteUser($params) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function testDeleteWithoutCard() {

// create a new address book
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
$books = $this->backend->getUsersOwnAddressBooks(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));

$bookId = $books[0]['id'];
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/DAV/HookManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testDeleteCalendar() {
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
$card->expects($this->once())->method('getAddressBooksForUser')->willReturn([
$card->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([
['id' => 'personal']
]);
$card->expects($this->once())->method('deleteAddressBook');
Expand Down