From: Bart Visscher Date: Mon, 28 Apr 2014 15:59:41 +0000 (+0200) Subject: Merge branch 'master' into type-hinting-sharing X-Git-Tag: v7.0.0alpha2~298^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=66b1ad0a9be76a179155c8ce6a47310f93e8bb42;p=nextcloud-server.git Merge branch 'master' into type-hinting-sharing Conflicts: apps/files_sharing/lib/share/file.php apps/files_sharing/tests/api.php lib/private/share/share.php --- 66b1ad0a9be76a179155c8ce6a47310f93e8bb42 diff --cc apps/files_sharing/lib/share/file.php index c375579b1a2,c0c9e0c107e..2c59bd3bf92 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@@ -147,44 -152,49 +152,54 @@@ class OC_Share_Backend_File implements } /** - * @param string $target + * @brief resolve reshares to return the correct source item + * @param array $source + * @return array source item */ - public static function getSource($target) { - if ($target == '') { - return false; + protected static function resolveReshares($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']; } - $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) { - $source['path'] = $source['path'].substr($target, strlen($folder)); + if (isset($fileOwner)) { + $source['fileOwner'] = $fileOwner; + } else { + \OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR); + } + + return $source; + } + ++ /** ++ * @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', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); + $source = \OCP\Share::getItemSharedWith('file', $mountPoint, \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; + return self::resolveReshares($source); } + \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::DEBUG); return false; } diff --cc lib/private/share/share.php index d9425b793c9,c0ce3a1d8af..21876bba831 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@@ -668,14 -751,15 +752,15 @@@ class Share extends \OC\Share\Constant /** * Set the permissions of an item for a specific user or group - * @param string Item type - * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK - * @param string User or group the item is being shared with - * @param int CRUDS permissions - * @return Returns true on success or false on failure + * @param string $itemType + * @param string $itemSource + * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK + * @param string $shareWith User or group the item is being shared with + * @param int $permissions CRUDS permissions + * @return boolean true on success or false on failure */ public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) { + $l = \OC_L10N::get('lib'); if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) { // Check if this item is a reshare and verify that the permissions