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']); $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); $isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);
if (!$isWritable){ 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)){ if ($view->file_exists($path)){

@ -55,20 +55,30 @@ class Storage {
$path = @$fileInfo[1]; $path = @$fileInfo[1];
if (!$path){ if (!$path){
throw new \Exception('File not found in cache'); throw new \Exception($fileId . ' can not be resolved');
} }
// Strip /files infront of the path $internalPath = preg_replace('/^\/?files/', '', $path);
$normalizedPath = preg_replace('/^\/?files/', '', $path); if (!\OC\Files\Filesystem::file_exists($internalPath)){
if (!\OC\Files\Filesystem::file_exists($path) $sharedInfo = \OCP\Share::getItemSharedWithBySource(
&& \OC\Files\Filesystem::file_exists('/Shared' . $normalizedPath) 'file',
&& \OC\Files\Filesystem::is_file('/Shared' . $normalizedPath) $fileId,
){ \OCP\Share::FORMAT_NONE,
null,
true
);
if (!$sharedInfo){
throw new \Exception($path . ' can not be resolved in shared cache');
}
// this file is shared // 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); $view = new \OC\Files\View('/' . $uid);
$relPath = '/files' . $filePath; if (!$view->file_exists($filePath)){
if (!$view->file_exists($relPath)){ throw new \Exception($filePath . ' doesn\'t exist');
throw new \Exception('Original document doesn\'t exist any more');
} }
if (!$view->is_file($relPath)){ if (!$view->is_file($filePath)){
throw new \Exception('Object ' . $relPath . ' is not a file.'); 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; \OC_FileProxy::$enabled = $proxyStatus;
return $newName; return $newName;
} }

Loading…
Cancel
Save