Resolve path to shared items for current user

pull/1/head
Victor Dubiniuk 11 years ago
parent 26fb9f25c3
commit 584d882c65

@ -75,11 +75,11 @@ class SessionController extends Controller{
}
$path = Storage::getFilePath($session['file_id']);
$view = new \OC\Files\View('/' . $session['owner']);
$view = new \OC\Files\View('/' . $uid);
$isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);
if (!$isWritable){
throw new \Exception('Document does not exist or is not writable for this user');
throw new \Exception($path . ' does not exist or is not writable for user ' . $uid);
}
if ($view->file_exists($path)){

@ -55,20 +55,30 @@ class Storage {
$path = @$fileInfo[1];
if (!$path){
throw new \Exception('File not found in cache');
throw new \Exception($fileId . ' can not be resolved');
}
// Strip /files infront of the path
$normalizedPath = preg_replace('/^\/?files/', '', $path);
if (!\OC\Files\Filesystem::file_exists($path)
&& \OC\Files\Filesystem::file_exists('/Shared' . $normalizedPath)
&& \OC\Files\Filesystem::is_file('/Shared' . $normalizedPath)
){
$internalPath = preg_replace('/^\/?files/', '', $path);
if (!\OC\Files\Filesystem::file_exists($internalPath)){
$sharedInfo = \OCP\Share::getItemSharedWithBySource(
'file',
$fileId,
\OCP\Share::FORMAT_NONE,
null,
true
);
if (!$sharedInfo){
throw new \Exception($path . ' can not be resolved in shared cache');
}
// this file is shared
$normalizedPath = '/Shared' . $normalizedPath;
$internalPath = 'Shared' . $sharedInfo['file_target'];
}
return $normalizedPath;
if (!\OC\Files\Filesystem::file_exists($internalPath)){
throw new \Exception($path . ' doesn\'t exist');
}
return 'files/' . $internalPath;
}
/**

@ -36,18 +36,17 @@ class View extends \OC\Files\View{
$view = new \OC\Files\View('/' . $uid);
$relPath = '/files' . $filePath;
if (!$view->file_exists($relPath)){
throw new \Exception('Original document doesn\'t exist any more');
if (!$view->file_exists($filePath)){
throw new \Exception($filePath . ' doesn\'t exist');
}
if (!$view->is_file($relPath)){
throw new \Exception('Object ' . $relPath . ' is not a file.');
if (!$view->is_file($filePath)){
throw new \Exception('Object ' . $filePath . ' is not a file.');
}
$newName = '/' . sha1($view->file_get_contents($relPath)) . '.odt';
$newName = '/' . sha1($view->file_get_contents($filePath)) . '.odt';
$view->copy($relPath, self::DOCUMENTS_DIRNAME . $newName);
$view->copy($filePath, self::DOCUMENTS_DIRNAME . $newName);
\OC_FileProxy::$enabled = $proxyStatus;
return $newName;
}

Loading…
Cancel
Save