1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

Contacts: Shared backend didn't always return correct permissions.

This commit is contained in:
Thomas Tanghus 2013-05-03 04:59:26 +02:00
parent 26cc08f553
commit f3a7d23e87

View File

@ -47,6 +47,9 @@ class Shared extends Database {
Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS
); );
foreach($this->addressbooks as &$addressBook) {
$addressBook['backend'] = $this->name;
}
return $this->addressbooks; return $this->addressbooks;
} }
@ -58,68 +61,63 @@ class Shared extends Database {
* @return mixed * @return mixed
*/ */
public function getAddressBook($addressbookid) { public function getAddressBook($addressbookid) {
$addressbook = \OCP\Share::getItemSharedWithBySource( $addressBook = \OCP\Share::getItemSharedWithBySource(
'addressbook', 'addressbook',
$addressbookid, $addressbookid,
Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS
); );
// Not sure if I'm doing it wrongly, or if its supposed to return // Not sure if I'm doing it wrongly, or if its supposed to return
// the info in an array? // the info in an array?
$addressBook = (isset($addressbook['permissions']) ? $addressbook : $addressbook[0]); $addressBook = (isset($addressBook['permissions']) ? $addressBook : $addressBook[0]);
$addressBook['backend'] = $this->name; $addressBook['backend'] = $this->name;
return $addressBook;
} }
/** /**
* Returns all contacts for a specific addressbook id. * Returns all contacts for a specific addressbook id.
* *
* TODO: Check for parent permissions
*
* @param string $addressbookid * @param string $addressbookid
* @param bool $omitdata Don't fetch the entire carddata or vcard. * @param bool $omitdata Don't fetch the entire carddata or vcard.
* @return array * @return array
*/ */
public function getContacts($addressbookid, $limit = null, $offset = null, $omitdata = false) { public function getContacts($addressbookid, $limit = null, $offset = null, $omitdata = false) {
//\OCP\Util::writeLog('contacts', __METHOD__.' addressbookid: '
// . $addressbookid, \OCP\Util::DEBUG);
$addressbook = \OCP\Share::getItemSharedWithBySource(
'addressbook',
$addressbookid,
Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS,
null, // parameters
true // includeCollection
);
\OCP\Util::writeLog('contacts', __METHOD__.' shared: '
. print_r($addressbook, true), \OCP\Util::DEBUG);
$addressbook = $this->getAddressBook($addressbookid); $addressBook = $this->getAddressBook($addressbookid);
$permissions = $addressbook['permissions']; if(!$addressBook) {
throw new \Exception('Shared Address Book not found: ' . $addressbookid, 404);
$cards = array();
try {
$qfields = $omitdata ? '`id`, `fullname` AS `displayname`, `lastmodified`' : '*';
$query = 'SELECT ' . $qfields . ' FROM `' . $this->cardsTableName
. '` WHERE `addressbookid` = ? ORDER BY `fullname`';
$stmt = \OCP\DB::prepare($query, $limit, $offset);
$result = $stmt->execute(array($addressbookid));
if (\OC_DB::isError($result)) {
\OC_Log::write('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return $cards;
}
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.', exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return $cards;
} }
$permissions = $addressBook['permissions'];
if(!is_null($result)) { $cards = parent::getContacts($addressbookid, $limit, $offset, $omitdata);
while( $row = $result->fetchRow()) {
$row['permissions'] = $permissions; foreach($cards as &$card) {
$cards[] = $row; $card['permissions'] = $permissions;
}
} }
return $cards; return $cards;
} }
/**
* Returns a specific contact.
*
* The $id for Database and Shared backends can be an array containing
* either 'id' or 'uri' to be able to play seamlessly with the
* CardDAV backend.
* @see \Database\getContact
*
* @param string $addressbookid
* @param mixed $id Contact ID
* @return array|false
*/
public function getContact($addressbookid, $id, $noCollection = false) {
$addressBook = $this->getAddressBook($addressbookid);
if(!$addressBook) {
throw new \Exception('Shared Address Book not found: ' . $addressbookid, 404);
}
$permissions = $addressBook['permissions'];
$card = parent::getContact($addressbookid, $id, $noCollection);
$card['permissions'] = $permissions;
return $card;
}
} }