@@ -25,6 +25,7 @@ use OCA\DAV\CardDAV\CardDavBackend; | |||
use OCA\DAV\Connector\Sabre\Principal; | |||
use OCP\IConfig; | |||
use OCP\IDBConnection; | |||
use OCP\IGroupManager; | |||
use OCP\ILogger; | |||
use OCP\IUserManager; | |||
use Symfony\Component\Console\Command\Command; | |||
@@ -40,12 +41,12 @@ class CreateAddressBook extends Command { | |||
/** @var \OCP\IDBConnection */ | |||
protected $dbConnection; | |||
/** @var IConfig */ | |||
private $config; | |||
/** @var ILogger */ | |||
private $logger; | |||
/** @var IGroupManager $groupManager */ | |||
private $groupManager; | |||
/** | |||
* @param IUserManager $userManager | |||
* @param IDBConnection $dbConnection | |||
@@ -53,14 +54,14 @@ class CreateAddressBook extends Command { | |||
* @param ILogger $logger | |||
*/ | |||
function __construct(IUserManager $userManager, | |||
IGroupManager $groupManager, | |||
IDBConnection $dbConnection, | |||
IConfig $config, | |||
ILogger $logger | |||
) { | |||
parent::__construct(); | |||
$this->userManager = $userManager; | |||
$this->groupManager = $groupManager; | |||
$this->dbConnection = $dbConnection; | |||
$this->config = $config; | |||
$this->logger = $logger; | |||
} | |||
@@ -82,7 +83,8 @@ class CreateAddressBook extends Command { | |||
throw new \InvalidArgumentException("User <$user> in unknown."); | |||
} | |||
$principalBackend = new Principal( | |||
$this->userManager | |||
$this->userManager, | |||
$this->groupManager | |||
); | |||
$name = $input->getArgument('name'); |
@@ -20,18 +20,8 @@ | |||
*/ | |||
namespace OCA\DAV\Command; | |||
use OCA\DAV\CardDAV\CardDavBackend; | |||
use OCA\DAV\CardDAV\Converter; | |||
use OCA\DAV\CardDAV\SyncService; | |||
use OCA\DAV\Connector\Sabre\Principal; | |||
use OCP\IConfig; | |||
use OCP\IDBConnection; | |||
use OCP\IUser; | |||
use OCP\IUserManager; | |||
use Sabre\CardDAV\Plugin; | |||
use Sabre\VObject\Component\VCard; | |||
use Sabre\VObject\Property\Text; | |||
use Sabre\VObject\Reader; | |||
use Symfony\Component\Console\Command\Command; | |||
use Symfony\Component\Console\Helper\ProgressBar; | |||
use Symfony\Component\Console\Input\InputArgument; |
@@ -105,17 +105,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { | |||
$result->closeCursor(); | |||
// query for shared calendars | |||
$principals = $this->principalBackend->getGroupMembership($principalUri); | |||
$principals[]= $principalUri; | |||
$query = $this->db->getQueryBuilder(); | |||
$query2 = $this->db->getQueryBuilder(); | |||
$query2->select(['resourceid']) | |||
->from('dav_shares') | |||
->where($query2->expr()->eq('principaluri', $query2->createParameter('principaluri'))) | |||
->where($query2->expr()->in('principaluri', $query2->createParameter('principaluri'))) | |||
->andWhere($query2->expr()->eq('type', $query2->createParameter('type'))); | |||
$result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) | |||
->from('addressbooks') | |||
->where($query->expr()->in('id', $query->createFunction($query2->getSQL()))) | |||
->setParameter('type', 'addressbook') | |||
->setParameter('principaluri', $principalUri) | |||
->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) | |||
->execute(); | |||
while($row = $result->fetch()) { |
@@ -29,9 +29,10 @@ | |||
namespace OCA\DAV\Connector\Sabre; | |||
use OCP\IGroup; | |||
use OCP\IGroupManager; | |||
use OCP\IUser; | |||
use OCP\IUserManager; | |||
use OCP\IConfig; | |||
use Sabre\DAV\Exception; | |||
use \Sabre\DAV\PropPatch; | |||
use Sabre\DAVACL\PrincipalBackend\BackendInterface; | |||
@@ -42,11 +43,15 @@ class Principal implements BackendInterface { | |||
/** @var IUserManager */ | |||
private $userManager; | |||
/** @var IGroupManager */ | |||
private $groupManager; | |||
/** | |||
* @param IUserManager $userManager | |||
*/ | |||
public function __construct(IUserManager $userManager) { | |||
public function __construct(IUserManager $userManager, IGroupManager $groupManager) { | |||
$this->userManager = $userManager; | |||
$this->groupManager = $groupManager; | |||
} | |||
/** | |||
@@ -127,24 +132,24 @@ class Principal implements BackendInterface { | |||
public function getGroupMembership($principal) { | |||
list($prefix, $name) = URLUtil::splitPath($principal); | |||
$group_membership = array(); | |||
if ($prefix === 'principals/users') { | |||
$principal = $this->getPrincipalByPath($principal); | |||
if (!$principal) { | |||
throw new Exception('Principal not found'); | |||
} | |||
// TODO: for now the user principal has only its own groups | |||
return array( | |||
'principals/users/'.$name.'/calendar-proxy-read', | |||
'principals/users/'.$name.'/calendar-proxy-write', | |||
// The addressbook groups are not supported in Sabre, | |||
// see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753 | |||
//'principals/'.$name.'/addressbook-proxy-read', | |||
//'principals/'.$name.'/addressbook-proxy-write', | |||
); | |||
$user = $this->userManager->get($name); | |||
$groups = $this->groupManager->getUserGroups($user); | |||
$groups = array_map(function($group) { | |||
/** @var IGroup $group */ | |||
return 'principals/groups/' . $group->getGID(); | |||
}, $groups); | |||
$groups[]= 'principals/users/'.$name.'/calendar-proxy-read'; | |||
$groups[]= 'principals/users/'.$name.'/calendar-proxy-write'; | |||
return $groups; | |||
} | |||
return $group_membership; | |||
return []; | |||
} | |||
/** |
@@ -37,7 +37,8 @@ class RootCollection extends SimpleCollection { | |||
$config = \OC::$server->getConfig(); | |||
$db = \OC::$server->getDatabaseConnection(); | |||
$userPrincipalBackend = new Principal( | |||
\OC::$server->getUserManager() | |||
\OC::$server->getUserManager(), | |||
\OC::$server->getGroupManager() | |||
); | |||
$groupPrincipalBackend = new GroupPrincipalBackend( | |||
\OC::$server->getGroupManager() |
@@ -23,21 +23,27 @@ | |||
namespace OCA\DAV\Tests\Unit\Connector\Sabre; | |||
use OCP\IGroupManager; | |||
use \Sabre\DAV\PropPatch; | |||
use OCP\IUserManager; | |||
use OCP\IConfig; | |||
class Principal extends \Test\TestCase { | |||
/** @var IUserManager */ | |||
private $userManager; | |||
/** @var \OCA\DAV\Connector\Sabre\Principal */ | |||
private $connector; | |||
/** @var IGroupManager */ | |||
private $groupManager; | |||
public function setUp() { | |||
$this->userManager = $this->getMockBuilder('\OCP\IUserManager') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->groupManager = $this->getMockBuilder('\OCP\IGroupManager') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->connector = new \OCA\DAV\Connector\Sabre\Principal($this->userManager); | |||
$this->connector = new \OCA\DAV\Connector\Sabre\Principal( | |||
$this->userManager, | |||
$this->groupManager); | |||
parent::setUp(); | |||
} | |||