mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Contacts: Namespace CardDAV backend.
This commit is contained in:
parent
ec24a73c48
commit
ac19b7f0f3
@ -6,14 +6,14 @@ OC::$CLASSPATH['OCA\Contacts\Hooks'] = 'contacts/lib/hooks.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\Share_Backend_Contact'] = 'contacts/lib/share/contact.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\Share_Backend_Addressbook'] = 'contacts/lib/share/addressbook.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\AddressbookProvider'] = 'contacts/lib/addressbookprovider.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAVPlugin'] = 'contacts/lib/sabre/plugin.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\VCardObject'] = 'contacts/lib/sabre/vcard.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\StringProperty'] = 'contacts/lib/sabre/stringproperty.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'contacts/lib/sabre/backend.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV_AddressBookRoot'] = 'contacts/lib/sabre/addressbookroot.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV_UserAddressBooks'] = 'contacts/lib/sabre/useraddressbooks.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV_AddressBook'] = 'contacts/lib/sabre/addressbook.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV_Card'] = 'contacts/lib/sabre/card.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\Backend'] = 'contacts/lib/sabre/backend.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\Plugin'] = 'contacts/lib/sabre/plugin.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\AddressBookRoot'] = 'contacts/lib/sabre/addressbookroot.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\UserAddressBooks'] = 'contacts/lib/sabre/useraddressbooks.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\AddressBook'] = 'contacts/lib/sabre/addressbook.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\CardDAV\Card'] = 'contacts/lib/sabre/card.php';
|
||||
OC::$CLASSPATH['OCA\Contacts\SearchProvider'] = 'contacts/lib/search.php';
|
||||
|
||||
require_once __DIR__ . '/../lib/sabre/vcard.php';
|
||||
|
@ -33,14 +33,14 @@ OC_App::loadApps($RUNTIME_APPTYPES);
|
||||
// Backends
|
||||
$authBackend = new OC_Connector_Sabre_Auth();
|
||||
$principalBackend = new OC_Connector_Sabre_Principal();
|
||||
$carddavBackend = new OC_Connector_Sabre_CardDAV();
|
||||
$carddavBackend = new OCA\Contacts\CardDAV\Backend();
|
||||
$requestBackend = new OC_Connector_Sabre_Request();
|
||||
|
||||
// Root nodes
|
||||
$principalCollection = new Sabre_CalDAV_Principal_Collection($principalBackend);
|
||||
$principalCollection->disableListing = true; // Disable listening
|
||||
|
||||
$addressBookRoot = new OC_Connector_Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend);
|
||||
$addressBookRoot = new OCA\Contacts\CardDAV\AddressBookRoot($principalBackend, $carddavBackend);
|
||||
$addressBookRoot->disableListing = true; // Disable listening
|
||||
|
||||
$nodes = array(
|
||||
@ -54,7 +54,7 @@ $server->httpRequest = $requestBackend;
|
||||
$server->setBaseUri($baseuri);
|
||||
// Add plugins
|
||||
$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend, 'ownCloud'));
|
||||
$server->addPlugin(new OCA\Contacts\CardDAVPlugin());
|
||||
$server->addPlugin(new OCA\Contacts\CardDAV\Plugin());
|
||||
$server->addPlugin(new Sabre_DAVACL_Plugin());
|
||||
$server->addPlugin(new Sabre_DAV_Browser_Plugin(false)); // Show something in the Browser, but no upload
|
||||
$server->addPlugin(new Sabre_CardDAV_VCFExportPlugin());
|
||||
|
@ -20,14 +20,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
use OCA\Contacts;
|
||||
|
||||
/**
|
||||
* This class overrides __construct to get access to $addressBookInfo and
|
||||
* $carddavBackend, Sabre_CardDAV_AddressBook::getACL() to return read/write
|
||||
* permissions based on user and shared state and it overrides
|
||||
* Sabre_CardDAV_AddressBook::getChild() and Sabre_CardDAV_AddressBook::getChildren()
|
||||
* to instantiate OC_Connector_Sabre_CardDAV_Cards.
|
||||
* to instantiate \OCA\Contacts\CardDAV\Cards.
|
||||
*/
|
||||
class OC_Connector_Sabre_CardDAV_AddressBook extends Sabre_CardDAV_AddressBook {
|
||||
class AddressBook extends \Sabre_CardDAV_AddressBook {
|
||||
|
||||
/**
|
||||
* CardDAV backend
|
||||
@ -43,7 +47,7 @@ class OC_Connector_Sabre_CardDAV_AddressBook extends Sabre_CardDAV_AddressBook {
|
||||
* @param array $addressBookInfo
|
||||
*/
|
||||
public function __construct(
|
||||
Sabre_CardDAV_Backend_Abstract $carddavBackend,
|
||||
\Sabre_CardDAV_Backend_Abstract $carddavBackend,
|
||||
array $addressBookInfo) {
|
||||
|
||||
$this->carddavBackend = $carddavBackend;
|
||||
@ -70,21 +74,21 @@ class OC_Connector_Sabre_CardDAV_AddressBook extends Sabre_CardDAV_AddressBook {
|
||||
$writeprincipal = $this->getOwner();
|
||||
$createprincipal = $this->getOwner();
|
||||
$deleteprincipal = $this->getOwner();
|
||||
$uid = OCA\Contacts\Addressbook::extractUserID($this->getOwner());
|
||||
$uid = Contacts\Addressbook::extractUserID($this->getOwner());
|
||||
|
||||
if($uid != OCP\USER::getUser()) {
|
||||
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']);
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_CREATE)) {
|
||||
$createprincipal = 'principals/' . OCP\USER::getUser();
|
||||
if($uid != \OCP\USER::getUser()) {
|
||||
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']);
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) {
|
||||
$createprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_READ)) {
|
||||
$readprincipal = 'principals/' . OCP\USER::getUser();
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
|
||||
$readprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_UPDATE)) {
|
||||
$writeprincipal = 'principals/' . OCP\USER::getUser();
|
||||
$writeprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_DELETE)) {
|
||||
$deleteprincipal = 'principals/' . OCP\USER::getUser();
|
||||
$deleteprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,8 +179,8 @@ class OC_Connector_Sabre_CardDAV_AddressBook extends Sabre_CardDAV_AddressBook {
|
||||
public function getChild($name) {
|
||||
|
||||
$obj = $this->carddavBackend->getCard($this->addressBookInfo['id'],$name);
|
||||
if (!$obj) throw new Sabre_DAV_Exception_NotFound('Card not found');
|
||||
return new OC_Connector_Sabre_CardDAV_Card($this->carddavBackend,$this->addressBookInfo,$obj);
|
||||
if (!$obj) throw new \Sabre_DAV_Exception_NotFound('Card not found');
|
||||
return new Card($this->carddavBackend,$this->addressBookInfo,$obj);
|
||||
|
||||
}
|
||||
|
||||
@ -190,7 +194,7 @@ class OC_Connector_Sabre_CardDAV_AddressBook extends Sabre_CardDAV_AddressBook {
|
||||
$objs = $this->carddavBackend->getCards($this->addressBookInfo['id']);
|
||||
$children = array();
|
||||
foreach($objs as $obj) {
|
||||
$children[] = new OC_Connector_Sabre_CardDAV_Card($this->carddavBackend,$this->addressBookInfo,$obj);
|
||||
$children[] = new Card($this->carddavBackend,$this->addressBookInfo,$obj);
|
||||
}
|
||||
return $children;
|
||||
|
@ -20,11 +20,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
/**
|
||||
* This class overrides Sabre_CardDAV_AddressBookRoot::getChildForPrincipal()
|
||||
* to instantiate OC_Connector_CardDAV_UserAddressBooks.
|
||||
*/
|
||||
class OC_Connector_Sabre_CardDAV_AddressBookRoot extends Sabre_CardDAV_AddressBookRoot {
|
||||
class AddressBookRoot extends \Sabre_CardDAV_AddressBookRoot {
|
||||
|
||||
/**
|
||||
* This method returns a node for a principal.
|
||||
@ -38,7 +40,7 @@ class OC_Connector_Sabre_CardDAV_AddressBookRoot extends Sabre_CardDAV_AddressBo
|
||||
*/
|
||||
public function getChildForPrincipal(array $principal) {
|
||||
|
||||
return new OC_Connector_Sabre_CardDAV_UserAddressBooks($this->carddavBackend, $principal['uri']);
|
||||
return new UserAddressBooks($this->carddavBackend, $principal['uri']);
|
||||
|
||||
}
|
||||
|
@ -20,10 +20,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This CardDAV backend uses PDO to store addressbooks
|
||||
*/
|
||||
class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
use OCA\Contacts;
|
||||
|
||||
class Backend extends \Sabre_CardDAV_Backend_Abstract {
|
||||
/**
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
@ -31,11 +32,11 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressBooksForUser($principaluri) {
|
||||
$data = OCA\Contacts\Addressbook::allWherePrincipalURIIs($principaluri);
|
||||
$data = Contacts\Addressbook::allWherePrincipalURIIs($principaluri);
|
||||
$addressbooks = array();
|
||||
|
||||
foreach($data as $i) {
|
||||
if($i['userid'] != OCP\USER::getUser()) {
|
||||
if($i['userid'] != \OCP\USER::getUser()) {
|
||||
$i['uri'] = $i['uri'] . '_shared_by_' . $i['userid'];
|
||||
}
|
||||
$addressbooks[] = array(
|
||||
@ -43,7 +44,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
'uri' => $i['uri'],
|
||||
'principaluri' => 'principals/'.$i['userid'],
|
||||
'{DAV:}displayname' => $i['displayname'],
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description'
|
||||
'{' . \Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description'
|
||||
=> $i['description'],
|
||||
'{http://calendarserver.org/ns/}getctag' => $i['ctag'],
|
||||
);
|
||||
@ -73,7 +74,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
case '{DAV:}displayname' :
|
||||
$name = $newvalue;
|
||||
break;
|
||||
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
|
||||
case '{' . \Sabre_CardDAV_Plugin::NS_CARDDAV
|
||||
. '}addressbook-description' :
|
||||
$description = $newvalue;
|
||||
break;
|
||||
@ -84,7 +85,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
}
|
||||
}
|
||||
|
||||
OCA\Contacts\Addressbook::edit($addressbookid, $name, $description);
|
||||
Contacts\Addressbook::edit($addressbookid, $name, $description);
|
||||
|
||||
return true;
|
||||
|
||||
@ -109,18 +110,18 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
case '{DAV:}displayname' :
|
||||
$displayname = $newvalue;
|
||||
break;
|
||||
case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV
|
||||
case '{' . \Sabre_CardDAV_Plugin::NS_CARDDAV
|
||||
. '}addressbook-description' :
|
||||
$description = $newvalue;
|
||||
break;
|
||||
default :
|
||||
throw new Sabre_DAV_Exception_BadRequest('Unknown property: '
|
||||
throw new \Sabre_DAV_Exception_BadRequest('Unknown property: '
|
||||
. $property);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OCA\Contacts\Addressbook::addFromDAVData(
|
||||
Contacts\Addressbook::addFromDAVData(
|
||||
$principaluri,
|
||||
$url,
|
||||
$name,
|
||||
@ -135,7 +136,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressBook($addressbookid) {
|
||||
OCA\Contacts\Addressbook::delete($addressbookid);
|
||||
Contacts\Addressbook::delete($addressbookid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +146,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return array
|
||||
*/
|
||||
public function getCards($addressbookid) {
|
||||
$data = OCA\Contacts\VCard::all($addressbookid);
|
||||
$data = Contacts\VCard::all($addressbookid);
|
||||
$cards = array();
|
||||
foreach($data as $i) {
|
||||
//OCP\Util::writeLog('contacts', __METHOD__.', uri: ' . $i['uri'], OCP\Util::DEBUG);
|
||||
@ -169,7 +170,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return array
|
||||
*/
|
||||
public function getCard($addressbookid, $carduri) {
|
||||
return OCA\Contacts\VCard::findWhereDAVDataIs($addressbookid, $carduri);
|
||||
return Contacts\VCard::findWhereDAVDataIs($addressbookid, $carduri);
|
||||
|
||||
}
|
||||
|
||||
@ -182,7 +183,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return bool
|
||||
*/
|
||||
public function createCard($addressbookid, $carduri, $carddata) {
|
||||
OCA\Contacts\VCard::addFromDAVData($addressbookid, $carduri, $carddata);
|
||||
Contacts\VCard::addFromDAVData($addressbookid, $carduri, $carddata);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -195,7 +196,7 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return bool
|
||||
*/
|
||||
public function updateCard($addressbookid, $carduri, $carddata) {
|
||||
return OCA\Contacts\VCard::editFromDAVData(
|
||||
return Contacts\VCard::editFromDAVData(
|
||||
$addressbookid, $carduri, $carddata
|
||||
);
|
||||
}
|
||||
@ -208,6 +209,6 @@ class OC_Connector_Sabre_CardDAV extends Sabre_CardDAV_Backend_Abstract {
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCard($addressbookid, $carduri) {
|
||||
return OCA\Contacts\VCard::deleteFromDAVData($addressbookid, $carduri);
|
||||
return Contacts\VCard::deleteFromDAVData($addressbookid, $carduri);
|
||||
}
|
||||
}
|
@ -20,11 +20,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
use OCA\Contacts;
|
||||
|
||||
/**
|
||||
* This class overrides Sabre_CardDAV_Card::getACL()
|
||||
* to return read/write permissions based on user and shared state.
|
||||
*/
|
||||
class OC_Connector_Sabre_CardDAV_Card extends Sabre_CardDAV_Card {
|
||||
class Card extends \Sabre_CardDAV_Card {
|
||||
|
||||
/**
|
||||
* Array with information about the containing addressbook
|
||||
@ -40,7 +44,7 @@ class OC_Connector_Sabre_CardDAV_Card extends Sabre_CardDAV_Card {
|
||||
* @param array $addressBookInfo
|
||||
* @param array $cardData
|
||||
*/
|
||||
public function __construct(Sabre_CardDAV_Backend_Abstract $carddavBackend, array $addressBookInfo, array $cardData) {
|
||||
public function __construct(\Sabre_CardDAV_Backend_Abstract $carddavBackend, array $addressBookInfo, array $cardData) {
|
||||
|
||||
$this->addressBookInfo = $addressBookInfo;
|
||||
parent::__construct($carddavBackend, $addressBookInfo, $cardData);
|
||||
@ -63,15 +67,15 @@ class OC_Connector_Sabre_CardDAV_Card extends Sabre_CardDAV_Card {
|
||||
|
||||
$readprincipal = $this->getOwner();
|
||||
$writeprincipal = $this->getOwner();
|
||||
$uid = OCA\Contacts\Addressbook::extractUserID($this->getOwner());
|
||||
$uid = Contacts\Addressbook::extractUserID($this->getOwner());
|
||||
|
||||
if($uid != OCP\USER::getUser()) {
|
||||
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']);
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_READ)) {
|
||||
$readprincipal = 'principals/' . OCP\USER::getUser();
|
||||
if($uid != \OCP\USER::getUser()) {
|
||||
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']);
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
|
||||
$readprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\PERMISSION_UPDATE)) {
|
||||
$writeprincipal = 'principals/' . OCP\USER::getUser();
|
||||
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) {
|
||||
$writeprincipal = 'principals/' . \OCP\USER::getUser();
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Contacts;
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
use Sabre\VObject;
|
||||
use OCA\Contacts;
|
||||
|
||||
/**
|
||||
* This class overrides Sabre_CardDAV_Plugin::validateVCard() to be able
|
||||
* to import partially invalid vCards by ignoring invalid lines and to
|
||||
* validate and upgrade using \OCA\Contacts\VCardObject.
|
||||
*/
|
||||
class CardDAVPlugin extends \Sabre_CardDAV_Plugin {
|
||||
class Plugin extends \Sabre_CardDAV_Plugin {
|
||||
|
||||
/**
|
||||
* Checks if the submitted vCard data is in fact, valid.
|
@ -20,11 +20,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Contacts\CardDAV;
|
||||
|
||||
/**
|
||||
* This class overrides Sabre_CardDAV_UserAddressBooks::getChildren()
|
||||
* to instantiate OC_Connector_Sabre_CardDAV_AddressBooks.
|
||||
* to instantiate \OCA\Contacts\CardDAV\AddressBooks.
|
||||
*/
|
||||
class OC_Connector_Sabre_CardDAV_UserAddressBooks extends Sabre_CardDAV_UserAddressBooks {
|
||||
class UserAddressBooks extends \Sabre_CardDAV_UserAddressBooks {
|
||||
|
||||
/**
|
||||
* Returns a list of addressbooks
|
||||
@ -36,7 +38,7 @@ class OC_Connector_Sabre_CardDAV_UserAddressBooks extends Sabre_CardDAV_UserAddr
|
||||
$addressbooks = $this->carddavBackend->getAddressbooksForUser($this->principalUri);
|
||||
$objs = array();
|
||||
foreach($addressbooks as $addressbook) {
|
||||
$objs[] = new OC_Connector_Sabre_CardDAV_AddressBook($this->carddavBackend, $addressbook);
|
||||
$objs[] = new AddressBook($this->carddavBackend, $addressbook);
|
||||
}
|
||||
return $objs;
|
||||
|
Loading…
Reference in New Issue
Block a user