Skip to content
Open
Changes from all 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
65 changes: 65 additions & 0 deletions lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ public function getContacts() {
$addressBooks = $this->contactsManager->getUserAddressBooks();
$result = [];
$userid = trim($this->userId);
// get addressbook ids
$bookids = [];
foreach ($contacts as $c) {
if (!in_array($c['addressbook-key'], $bookids)) {
array_push($bookids, $c['addressbook-key']);
}
}
// determine if addressbooks are enabled
$bookIsEnabled = $this->getBookIsEnabled($bookids);

foreach ($contacts as $c) {
if (!$bookIsEnabled[$c['addressbook-key']]) {
continue;
}
$addressBookUri = $addressBooks[$c['addressbook-key']]->getUri();
$uid = trim($c['UID']);
// we don't give users, just contacts
Expand Down Expand Up @@ -117,6 +130,44 @@ public function getContacts() {
return new DataResponse($result);
}

private function getBookIsEnabled($bookids) {
$bookIsEnabled = [];
$qb = $this->qb;
foreach ($bookids as $bookid) {
// first get the address book uri in oc_addressbooks
$qb->select('uri', 'principaluri')
->from('addressbooks')
->where($qb->expr()->eq('id', $qb->createNamedParameter($bookid, IQueryBuilder::PARAM_INT)));
$req = $qb->execute();
$uri = null;
$principaluri = null;
while ($row = $req->fetch()) {
$uri = $row['uri'];
$principaluri = $row['principaluri'];
}
$req->closeCursor();
$qb = $qb->resetQueryParts();
// then check its {http://owncloud.org/ns}enabled property in oc_properties
if ($uri !== null) {
$propertypath = str_replace('principals/users/', 'addressbooks/users/', $principaluri) . '/' . $uri;
$qb->select('propertyvalue')
->from('properties')
->where($qb->expr()->eq('propertypath', $qb->createNamedParameter($propertypath, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('propertyname', $qb->createNamedParameter('{http://owncloud.org/ns}enabled', IQueryBuilder::PARAM_STR)));
$req = $qb->execute();
$propertyvalue = null;
while ($row = $req->fetch()) {
$propertyvalue = intval($row['propertyvalue']);
}
$req->closeCursor();
$qb = $qb->resetQueryParts();

$bookIsEnabled[$bookid] = ($propertyvalue === null or $propertyvalue === 1);
}
}
return $bookIsEnabled;
}

private function N2FN(string $n) {
if ($n) {
$spl = explode($n, ';');
Expand All @@ -141,7 +192,21 @@ public function getAllContacts() {
$booksReadOnly = $this->getAddressBooksReadOnly();
$result = [];
$userid = trim($this->userId);

// get addressbook ids
$bookids = [];
foreach ($contacts as $c) {
if (!in_array($c['addressbook-key'], $bookids)) {
array_push($bookids, $c['addressbook-key']);
}
}
// determine if addressbooks are enabled
$bookIsEnabled = $this->getBookIsEnabled($bookids);

foreach ($contacts as $c) {
if (!$bookIsEnabled[$c['addressbook-key']]) {
continue;
}
$uid = trim($c['UID']);
// we don't give users, just contacts
if (strcmp($c['URI'], 'Database:'.$c['UID'].'.vcf') !== 0 and
Expand Down