Beispiel #1
0
 /**
  * Sets up the backend.
  */
 public function __construct()
 {
     $oPdo = \CApi::GetPDO();
     $dbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix');
     $this->oApiUsersManager = \CApi::Manager('users');
     parent::__construct($oPdo, $dbPrefix . Constants::T_PRINCIPALS, $dbPrefix . Constants::T_GROUPMEMBERS);
 }
Beispiel #2
0
 /**
  * Updates the list of group members for a group principal.
  *
  * The principals should be passed as a list of uri's.
  *
  * @param string $principal
  * @param array $members
  * @return void
  */
 public function setGroupMemberSet($principal, array $members)
 {
     // Grabbing the list of principal id's.
     $stmt = $this->pdo->prepare('SELECT id, uri FROM ' . $this->tableName . ' WHERE uri IN (? ' . str_repeat(', ? ', count($members)) . ');');
     $stmt->execute(array_merge(array($principal), $members));
     $memberIds = array();
     $principalId = null;
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         if ($row['uri'] == $principal) {
             $principalId = $row['id'];
         } else {
             $memberIds[] = $row['id'];
         }
     }
     if (!$principalId) {
         throw new DAV\Exception('Principal not found');
     }
     // Wiping out old members
     $stmt = $this->pdo->prepare('DELETE FROM ' . $this->groupMembersTableName . ' WHERE principal_id = ?;');
     $stmt->execute(array($principalId));
     foreach ($memberIds as $memberId) {
         $stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
         $stmt->execute(array($principalId, $memberId));
     }
 }
Beispiel #3
0
 function getPDO()
 {
     if (!SABRE_HASSQLITE) {
         $this->markTestSkipped('SQLite driver is not available');
     }
     $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/pdobackend');
     $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $pdo->query('CREATE TABLE principals (id INTEGER PRIMARY KEY ASC, uri TEXT, email VARCHAR(80), displayname VARCHAR(80))');
     $pdo->query('INSERT INTO principals VALUES (1, "principals/user","*****@*****.**","User")');
     $pdo->query('INSERT INTO principals VALUES (2, "principals/group","*****@*****.**","Group")');
     $pdo->query("CREATE TABLE groupmembers (\n                id INTEGER PRIMARY KEY ASC,\n                principal_id INT,\n                member_id INT,\n                UNIQUE(principal_id, member_id)\n        );");
     $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (2,1)");
     return $pdo;
 }
Beispiel #4
0
 function testUpdatePrincipalUnknownField()
 {
     $pdo = $this->getPDO();
     $backend = new PDO($pdo);
     $result = $backend->updatePrincipal('principals/user', array('{DAV:}displayname' => 'pietje', '{http://sabredav.org/ns}vcard-url' => 'blabla', '{DAV:}unknown' => 'foo'));
     $this->assertEquals(array(424 => array('{DAV:}displayname' => null, '{http://sabredav.org/ns}vcard-url' => null), 403 => array('{DAV:}unknown' => null)), $result);
     $this->assertEquals(array('id' => '1', 'uri' => 'principals/user', '{DAV:}displayname' => 'User', '{http://sabredav.org/ns}email-address' => '*****@*****.**'), $backend->getPrincipalByPath('principals/user'));
 }
 function testUpdatePrincipalUnknownField()
 {
     $pdo = $this->getPDO();
     $backend = new PDO($pdo);
     $propPatch = new DAV\PropPatch(['{DAV:}displayname' => 'pietje', '{http://sabredav.org/ns}vcard-url' => 'blabla', '{DAV:}unknown' => 'foo']);
     $backend->updatePrincipal('principals/user', $propPatch);
     $result = $propPatch->commit();
     $this->assertFalse($result);
     $this->assertEquals(array('{DAV:}displayname' => 424, '{http://sabredav.org/ns}vcard-url' => 424, '{DAV:}unknown' => 403), $propPatch->getResult());
     $this->assertEquals(array('id' => '1', 'uri' => 'principals/user', '{DAV:}displayname' => 'User', '{http://sabredav.org/ns}email-address' => '*****@*****.**'), $backend->getPrincipalByPath('principals/user'));
 }
Beispiel #6
0
 /**
  * Creates a new principal.
  *
  * This method receives a full path for the new principal. The mkCol object
  * contains any additional webdav properties specified during the creation
  * of the principal.
  *
  * @param string $path
  * @param MkCol $mkCol
  * @return void
  */
 function createPrincipal($path, MkCol $mkCol)
 {
     $stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
     $stmt->execute([$path]);
     $this->updatePrincipal($path, $mkCol);
 }
Beispiel #7
0
 function testFindByUri()
 {
     $pdo = $this->getPDO();
     $backend = new PDO($pdo);
     $this->assertEquals('principals/user', $backend->findByUri('mailto:user@example.org', 'principals'));
 }