1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Fix and re-activate Contact sharing backend.

While not needed for actual contacts sharing (which is solely done via
the Addressbook sharing backend), we need its isValidSource() function
in core's \OC\Tags::getIdsForTag() (which implements \OCP\ITags::getIdsForTag()).
It is required there to test if the items that are tagged with a given
tag are actually allowed to be accessed by the user, i.e. owned by the
user or someone who is sharing it with the user.
This commit is contained in:
Bernhard Reiter 2014-09-29 11:20:57 +02:00
parent e8a735a210
commit 51d6783240
2 changed files with 27 additions and 13 deletions

View File

@ -56,7 +56,7 @@ $api->connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalende
\OCP\Util::addscript('contacts', 'admin');
\OC_Search::registerProvider('OCA\Contacts\Search\Provider');
//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact');
\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share\Contact');
\OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share\Addressbook', 'contact');
//\OCP\App::registerPersonal('contacts','personalsettings');
\OCP\App::registerAdmin('contacts', 'admin');

View File

@ -20,42 +20,56 @@
*/
namespace OCA\Contacts\Share;
use OCA\Contacts;
use OCA\Contacts\App;
class Contact implements \OCP\Share_Backend {
const FORMAT_CONTACT = 0;
private static $contact;
/**
* @var \OCA\Contacts\App;
*/
public $app;
/**
* @var \OCA\Contacts\Backend\Database;
*/
public $backend;
public function __construct() {
// Currently only share
$this->backend = new Backend\Database();
$this->app = new App(\OCP\User::getUser());
$this->backend = $this->app->getBackend('local');
}
public function isValidSource($itemSource, $uidOwner) {
self::$contact = VCard::find($itemSource);
if (self::$contact) {
return true;
// TODO: Cache address books.
$app = new App($uidOwner);
$userAddressBooks = $app->getAddressBooksForUser();
foreach ($userAddressBooks as $addressBook) {
if ($addressBook->childExists($itemSource)) {
return true;
}
}
return false;
}
public function generateTarget($itemSource, $shareWith, $exclude = null) {
// TODO Get default addressbook and check for conflicts
return self::$contact['fullname'];
$contact = $this->backend->getContact(null, $itemSource,
array('noCollection' => true));
return $contact['fullname'];
}
public function formatItems($items, $format, $parameters = null) {
$contacts = array();
if ($format == self::FORMAT_CONTACT) {
foreach ($items as $item) {
$contact = VCard::find($item['item_source']);
$contact['fullname'] = $item['item_target'];
$contacts[] = $contact;
$contacts[] = $this->backend->getContact(null, $item,
array('noCollection' => true));
}
}
return $contacts;
}
}
}