コード例 #1
0
 /**
  * @dataProvider providesReadOnlyInfo
  */
 public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */
     $backend = $this->getMockBuilder('OCA\\DAV\\CardDAV\\CardDavBackend')->disableOriginalConstructor()->getMock();
     $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
     $calendarInfo = ['principaluri' => 'user2', 'id' => 666, 'uri' => 'default'];
     if (!is_null($readOnlyValue)) {
         $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue;
     }
     if ($hasOwnerSet) {
         $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
     }
     $c = new AddressBook($backend, $calendarInfo);
     $acl = $c->getACL();
     $childAcl = $c->getChildACL();
     $expectedAcl = [['privilege' => '{DAV:}read', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true], ['privilege' => '{DAV:}write', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true]];
     if ($hasOwnerSet) {
         $expectedAcl[] = ['privilege' => '{DAV:}read', 'principal' => 'user2', 'protected' => true];
         if ($expectsWrite) {
             $expectedAcl[] = ['privilege' => '{DAV:}write', 'principal' => 'user2', 'protected' => true];
         }
     }
     $this->assertEquals($expectedAcl, $acl);
     $this->assertEquals($expectedAcl, $childAcl);
 }
コード例 #2
0
ファイル: addressbooktest.php プロジェクト: gvde/core
 /**
  * @expectedException \Sabre\DAV\Exception\Forbidden
  */
 public function testPropPatch()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */
     $backend = $this->getMockBuilder('OCA\\DAV\\CardDAV\\CardDavBackend')->disableOriginalConstructor()->getMock();
     $calendarInfo = ['{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', 'id' => 666];
     $c = new AddressBook($backend, $calendarInfo);
     $c->propPatch(new PropPatch([]));
 }
コード例 #3
0
ファイル: addressbooktest.php プロジェクト: farukuzun/core-1
 /**
  * @expectedException \Sabre\DAV\Exception\Forbidden
  */
 public function testDeleteFromGroup()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */
     $backend = $this->getMockBuilder('OCA\\DAV\\CardDAV\\CardDavBackend')->disableOriginalConstructor()->getMock();
     $backend->expects($this->never())->method('updateShares');
     $backend->method('getShares')->willReturn([['href' => 'principal:group2']]);
     $calendarInfo = ['{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', 'id' => 666];
     $c = new AddressBook($backend, $calendarInfo);
     $c->delete();
 }
コード例 #4
0
 /**
  * @return mixed
  * @since 5.0.0
  */
 public function getPermissions()
 {
     $permissions = $this->addressBook->getACL();
     $result = 0;
     foreach ($permissions as $permission) {
         switch ($permission['privilege']) {
             case '{DAV:}read':
                 $result |= Constants::PERMISSION_READ;
                 break;
             case '{DAV:}write':
                 $result |= Constants::PERMISSION_CREATE;
                 $result |= Constants::PERMISSION_UPDATE;
                 break;
             case '{DAV:}all':
                 $result |= Constants::PERMISSION_ALL;
                 break;
         }
     }
     return $result;
 }
コード例 #5
0
ファイル: carddavbackend.php プロジェクト: Juraganet/core
 /**
  * @param AddressBook $addressBook
  * @param string $element
  */
 private function shareWith($addressBook, $element)
 {
     $user = $element['href'];
     $parts = explode(':', $user, 2);
     if ($parts[0] !== 'principal') {
         return;
     }
     $p = $this->principalBackend->getPrincipalByPath($parts[1]);
     if (is_null($p)) {
         return;
     }
     // remove the share if it already exists
     $this->unshare($addressBook->getBookId(), $element['href']);
     $access = self::ACCESS_READ;
     if (isset($element['readOnly'])) {
         $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
     }
     $newUri = sha1($addressBook->getName() . $addressBook->getOwner());
     $query = $this->db->getQueryBuilder();
     $query->insert('dav_shares')->values(['principaluri' => $query->createNamedParameter($parts[1]), 'uri' => $query->createNamedParameter($newUri), 'type' => $query->createNamedParameter('addressbook'), 'access' => $query->createNamedParameter($access), 'resourceid' => $query->createNamedParameter($addressBook->getBookId())]);
     $query->execute();
 }