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

Backends were instantiated before user was logged in and broke CardDAV

fix #186
This commit is contained in:
Thomas Tanghus 2013-09-04 20:10:43 +02:00
parent dcb9ad4356
commit 0d628fb766
3 changed files with 16 additions and 12 deletions

View File

@ -35,10 +35,8 @@ $authBackend = new OC_Connector_Sabre_Auth();
$principalBackend = new OC_Connector_Sabre_Principal();
$addressbookbackends = array();
$addressbookbackends[] = new OCA\Contacts\Backend\Ldap();
$addressbookbackends[] = new OCA\Contacts\Backend\Shared();
$addressbookbackends[] = new OCA\Contacts\Backend\Database();
$carddavBackend = new OCA\Contacts\CardDAV\Backend($addressbookbackends);
$addressbookbackends[] = new OCA\Contacts\Backend\Database(\OCP\User::getUser());
$carddavBackend = new OCA\Contacts\CardDAV\Backend(['local', 'shared']);
$requestBackend = new OC_Connector_Sabre_Request();
// Root nodes

View File

@ -53,6 +53,12 @@ abstract class AbstractBackend {
*/
public $name;
/**
* The current usert.
* @var string
*/
public $userid;
protected $possibleContactPermissions = array(
\OCP\PERMISSION_CREATE => 'createContact',
\OCP\PERMISSION_READ => 'getContact',

View File

@ -27,7 +27,6 @@ use OCA\Contacts;
class Backend extends \Sabre_CardDAV_Backend_Abstract {
public function __construct($backends) {
//\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
$this->backends = $backends;
}
@ -39,8 +38,10 @@ class Backend extends \Sabre_CardDAV_Backend_Abstract {
*/
public function getAddressBooksForUser($principaluri) {
$app = new Contacts\App();
$userAddressBooks = array();
foreach($this->backends as $backend) {
foreach($this->backends as $backendName) {
$backend = $app->getBackend($backendName);
$addressBooks = $backend->getAddressBooksForUser();
if (is_array($addressBooks)) {
@ -176,7 +177,6 @@ class Backend extends \Sabre_CardDAV_Backend_Abstract {
$cards = array();
foreach($contacts as $contact) {
//OCP\Util::writeLog('contacts', __METHOD__.', uri: ' . $i['uri'], OCP\Util::DEBUG);
$cards[] = array(
'id' => $contact['id'],
//'carddata' => $i['carddata'],
@ -262,11 +262,11 @@ class Backend extends \Sabre_CardDAV_Backend_Abstract {
* @return array(string, \OCA\Contacts\Backend\AbstractBackend)
*/
public function getBackendForAddressBook($addressbookid) {
list($backendName, $id) = explode('::', $addressbookid);
foreach($this->backends as $backend) {
if($backend->name === $backendName && $backend->hasAddressBook($id)) {
return array($id, $backend);
}
list($BackendName, $id) = explode('::', $addressbookid);
$app = new Contacts\App();
$backend = $app->getBackend($backendName);
if($backend->name === $backendName && $backend->hasAddressBook($id)) {
return array($id, $backend);
}
throw new \Sabre_DAV_Exception_NotFound('Backend not found: ' . $addressbookid);
}