Esempio n. 1
0
 private static function getUidAndFilename($filename)
 {
     if (\OCP\App::isEnabled('files_sharing') && substr($filename, 0, 7) == '/Shared' && ($source = \OCP\Share::getItemSharedWith('file', substr($filename, 7), \OC_Share_Backend_File::FORMAT_SHARED_STORAGE))) {
         $filename = $source['path'];
         $pos = strpos($filename, '/files', 1);
         $uid = substr($filename, 1, $pos - 1);
         $filename = substr($filename, $pos + 6);
     } else {
         $uid = \OCP\User::getUser();
     }
     return array($uid, $filename);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function find($privateUri, $userId)
 {
     // different formats for privateUri
     // calendar::$privateUri
     // object::$userId
     list($itemType, $itemTarget) = explode('::', $privateUri, 1);
     if ($itemType === 'calendar') {
         return Share::getItemSharedWith($itemType, $itemTarget, ShareTypes::ENTITY);
     } elseif ($itemType === 'object') {
         $calendars = Share::getItemsShared($itemType, ShareTypes::GROUPED);
         if (!isset($calendars[$itemTarget])) {
             throw new BackendUtils\DoesNotExistException();
         }
         return $calendars[$itemTarget]['calendar'];
     } else {
         throw new BackendUtils\DoesNotExistException();
     }
 }
Esempio n. 3
0
 /**
  * @param string $target
  * @param string $mountPoint
  * @param string $itemType
  * @return array|false source item
  */
 public static function getSource($target, $mountPoint, $itemType)
 {
     if ($itemType === 'folder') {
         $source = \OCP\Share::getItemSharedWith('folder', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
         if ($source && $target !== '') {
             $source['path'] = $source['path'] . '/' . $target;
         }
     } else {
         $source = \OCP\Share::getItemSharedWith('file', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
     }
     if ($source) {
         return self::resolveReshares($source);
     }
     \OCP\Util::writeLog('files_sharing', 'File source not found for: ' . $target, \OCP\Util::DEBUG);
     return false;
 }
Esempio n. 4
0
 public function testShareWithGroupAndUserBothHaveTheSameId()
 {
     $this->shareUserTestFileWithUser($this->user1, $this->groupAndUser);
     \OC_User::setUserId($this->groupAndUser);
     $this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), '"groupAndUser"-User does not see the file but it was shared with him');
     \OC_User::setUserId($this->user2);
     $this->assertEquals(array(), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), 'User2 sees test.txt but it was only shared with the user "groupAndUser" and not with group');
     \OC_User::setUserId($this->user1);
     $this->assertTrue(\OCP\Share::unshareAll('test', 'test.txt'));
     $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_GROUP, $this->groupAndUser, \OCP\Constants::PERMISSION_READ), 'Failed asserting that user 1 successfully shared text.txt with group 1.');
     \OC_User::setUserId($this->groupAndUser);
     $this->assertEquals(array(), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), '"groupAndUser"-User sees test.txt but it was only shared with the group "groupAndUser" and not with the user');
     \OC_User::setUserId($this->user2);
     $this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), 'User2 does not see test.txt but it was shared with the group "groupAndUser"');
     \OC_User::setUserId($this->user1);
     $this->assertTrue(\OCP\Share::unshareAll('test', 'test.txt'));
 }
Esempio n. 5
0
 /**
  * @param string $target
  * @param string $mountPoint
  * @param string $itemType
  * @return array|false source item
  */
 public static function getSource($target, $mountPoint, $itemType)
 {
     if ($itemType === 'folder') {
         $source = \OCP\Share::getItemSharedWith('folder', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
         if ($source && $target !== '') {
             // note: in case of ext storage mount points the path might be empty
             // which would cause a leading slash to appear
             $source['path'] = ltrim($source['path'] . '/' . $target, '/');
         }
     } else {
         $source = \OCP\Share::getItemSharedWith('file', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
     }
     if ($source) {
         return self::resolveReshares($source);
     }
     \OCP\Util::writeLog('files_sharing', 'File source not found for: ' . $target, \OCP\Util::DEBUG);
     return false;
 }
Esempio n. 6
0
 /**
  * if a file was shared as group share and as individual share they should be grouped
  */
 public function testGroupingOfShares()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Files_Sharing::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_READ);
     $this->assertTrue($result);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_UPDATE);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return exactly one shares created from testCreateShare()
     $this->assertSame(1, count($result));
     $share = reset($result);
     $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
     \OC\Files\Filesystem::rename($this->filename, $this->filename . '-renamed');
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return exactly one shares created from testCreateShare()
     $this->assertSame(1, count($result));
     $share = reset($result);
     $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
     $this->assertSame($this->filename . '-renamed', $share['file_target']);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // unshare user share
     $result = \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return the remaining group share
     $this->assertSame(1, count($result));
     $share = reset($result);
     // only the group share permissions should be available now
     $this->assertSame(\OCP\Constants::PERMISSION_READ, $share['permissions']);
     $this->assertSame($this->filename . '-renamed', $share['file_target']);
 }
Esempio n. 7
0
 public static function getSource($target)
 {
     if ($target == '') {
         return false;
     }
     $target = '/' . $target;
     $target = rtrim($target, '/');
     $pos = strpos($target, '/', 1);
     // Get shared folder name
     if ($pos !== false) {
         $folder = substr($target, 0, $pos);
         $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
         if ($source) {
             // note: in case of ext storage mount points the path might be empty
             // which would cause a leading slash to appear
             $source['path'] = ltrim($source['path'] . substr($target, strlen($folder)), '/');
         }
     } else {
         $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
     }
     if ($source) {
         if (isset($source['parent'])) {
             $parent = $source['parent'];
             while (isset($parent)) {
                 $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
                 $item = $query->execute(array($parent))->fetchRow();
                 if (isset($item['parent'])) {
                     $parent = $item['parent'];
                 } else {
                     $fileOwner = $item['uid_owner'];
                     break;
                 }
             }
         } else {
             $fileOwner = $source['uid_owner'];
         }
         $source['fileOwner'] = $fileOwner;
         return $source;
     }
     \OCP\Util::writeLog('files_sharing', 'File source not found for: ' . $target, \OCP\Util::DEBUG);
     return false;
 }