Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/maps.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2019-10-14 20:22:36 +0300
committerJulien Veyssier <eneiluj@posteo.net>2019-10-14 20:22:36 +0300
commit004ede2a6aee93788bcc2e9c341f1ee5354cc962 (patch)
tree556d937bd3c0e71cda0b4c24fa1ac9c2b6a9247e
parent9a6aec01f70223b90e18865c22314a917c63be62 (diff)
refs #169 don't get contacts from disabled address booksfix-issue169
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
-rw-r--r--lib/Controller/ContactsController.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/Controller/ContactsController.php b/lib/Controller/ContactsController.php
index 3402b22e..3df3067d 100644
--- a/lib/Controller/ContactsController.php
+++ b/lib/Controller/ContactsController.php
@@ -58,7 +58,20 @@ class ContactsController extends Controller {
$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
@@ -117,6 +130,44 @@ class ContactsController extends Controller {
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, ';');
@@ -141,7 +192,21 @@ class ContactsController extends Controller {
$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