on reshares we now recursively move to the root of all reshares - therefore some code has been refactured and added as a new public function

This commit is contained in:
Thomas Müller 2013-07-05 17:39:41 +02:00
parent 0202d47f7a
commit e159cbf527
3 changed files with 39 additions and 31 deletions

View File

@ -27,25 +27,24 @@ if (empty($_POST['dirToken'])) {
if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) {
OCP\JSON::checkLoggedIn();
} else {
// resolve reshares
$rootLinkItem = OCP\Share::resolveReShare($linkItem);
// Setup FS with owner
OC_Util::setupFS($rootLinkItem['uid_owner']);
// The token defines the target directory (security reasons)
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
$dir = sprintf(
"/%s/%s",
$linkItem['file_target'],
$path,
isset($_POST['subdir']) ? $_POST['subdir'] : ''
);
// handle reshare
if (!empty($linkItem['parent'])) {
$dir = '/Shared'.$dir;
}
if (!$dir || empty($dir) || $dir === false) {
OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.')))));
die();
}
// Setup FS with owner
OC_Util::setupFS($linkItem['uid_owner']);
}
}
@ -81,17 +80,17 @@ $files = $_FILES['files'];
$error = '';
$maxUploadFilesize = OCP\Util::maxUploadFilesize($dir);
$maxHumanFilesize = OCP\Util::humanFileSize($maxUploadFilesize);
$maxUploadFileSize = $storageStats['uploadMaxFilesize'];
$maxHumanFileSize = OCP\Util::humanFileSize($maxUploadFileSize);
$totalSize = 0;
foreach ($files['size'] as $size) {
$totalSize += $size;
}
if ($maxUploadFilesize >= 0 and $totalSize > $maxUploadFilesize) {
if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'),
'uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize)));
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize)));
exit();
}
@ -113,8 +112,8 @@ if (strpos($dir, '..') === false) {
'id' => $meta['fileid'],
'name' => basename($target),
'originalname' => $files['name'][$i],
'uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize
);
}
}

View File

@ -27,23 +27,9 @@ if (isset($_GET['t'])) {
$type = $linkItem['item_type'];
$fileSource = $linkItem['file_source'];
$shareOwner = $linkItem['uid_owner'];
$fileOwner = null;
$path = null;
if (isset($linkItem['parent'])) {
$parent = $linkItem['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 = $shareOwner;
}
$rootLinkItem = OCP\Share::resolveReShare($linkItem);
$fileOwner = $rootLinkItem['uid_owner'];
if (isset($fileOwner)) {
OC_Util::tearDownFS();
OC_Util::setupFS($fileOwner);

View File

@ -291,6 +291,29 @@ class Share {
return $result->fetchRow();
}
/**
* @brief resolves reshares down to the last real share
* @param $linkItem
* @return $fileOwner
*/
public static function resolveReShare($linkItem)
{
if (isset($linkItem['parent'])) {
$parent = $linkItem['parent'];
while (isset($parent)) {
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `id` = ?', 1);
$item = $query->execute(array($parent))->fetchRow();
if (isset($item['parent'])) {
$parent = $item['parent'];
} else {
return $item;
}
}
}
return $linkItem;
}
/**
* @brief Get the shared items of item type owned by the current user
* @param string Item type