get the actual user instead of a federated cloud id

$view->getUidAndFilename($filename); returns the federated cloud id in case of
a federated share. But in this case we need the local user who "owns" the file
which is the current logged in user in case of a federated share
This commit is contained in:
Bjoern Schiessle 2016-02-18 09:57:29 +01:00
parent ac1c3d27b7
commit 8985181305
1 changed files with 43 additions and 15 deletions

View File

@ -29,7 +29,9 @@
namespace OCA\Files_Sharing;
use OC\Files\Filesystem;
use OC\Files\View;
use OCP\Files\NotFoundException;
use OCP\User;
class Helper {
@ -78,7 +80,7 @@ class Helper {
}
try {
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
$path = Filesystem::getPath($linkItem['file_source']);
} catch (NotFoundException $e) {
\OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
\OC_Response::setStatus(404);
@ -103,8 +105,8 @@ class Helper {
$basePath = $path;
if ($relativePath !== null && \OC\Files\Filesystem::isReadable($basePath . $relativePath)) {
$path .= \OC\Files\Filesystem::normalizePath($relativePath);
if ($relativePath !== null && Filesystem::isReadable($basePath . $relativePath)) {
$path .= Filesystem::normalizePath($relativePath);
}
return array(
@ -168,11 +170,11 @@ class Helper {
public static function getSharesFromItem($target) {
$result = array();
$owner = \OC\Files\Filesystem::getOwner($target);
\OC\Files\Filesystem::initMountPoints($owner);
$info = \OC\Files\Filesystem::getFileInfo($target);
$ownerView = new \OC\Files\View('/'.$owner.'/files');
if ( $owner != \OCP\User::getUser() ) {
$owner = Filesystem::getOwner($target);
Filesystem::initMountPoints($owner);
$info = Filesystem::getFileInfo($target);
$ownerView = new View('/'.$owner.'/files');
if ( $owner != User::getUser() ) {
$path = $ownerView->getPath($info['fileid']);
} else {
$path = $target;
@ -205,8 +207,34 @@ class Helper {
return $result;
}
/**
* get the UID of the owner of the file and the path to the file relative to
* owners files folder
*
* @param $filename
* @return array
* @throws \OC\User\NoUserException
*/
public static function getUidAndFilename($filename) {
return Filesystem::getView()->getUidAndFilename($filename);
$uid = Filesystem::getOwner($filename);
$userManager = \OC::$server->getUserManager();
// if the user with the UID doesn't exists, e.g. because the UID points
// to a remote user with a federated cloud ID we use the current logged-in
// user. We need a valid local user to create the share
if (!$userManager->userExists($uid)) {
$uid = User::getUser();
}
Filesystem::initMountPoints($uid);
if ( $uid != User::getUser() ) {
$info = Filesystem::getFileInfo($filename);
$ownerView = new View('/'.$uid.'/files');
try {
$filename = $ownerView->getPath($info['fileid']);
} catch (NotFoundException $e) {
$filename = null;
}
}
return [$uid, $filename];
}
/**
@ -234,7 +262,7 @@ class Helper {
*
* @param string $path
* @param array $excludeList
* @param \OC\Files\View $view
* @param View $view
* @return string $path
*/
public static function generateUniqueTarget($path, $excludeList, $view) {
@ -244,7 +272,7 @@ class Helper {
$dir = $pathinfo['dirname'];
$i = 2;
while ($view->file_exists($path) || in_array($path, $excludeList)) {
$path = \OC\Files\Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
$path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
$i++;
}
@ -278,15 +306,15 @@ class Helper {
*/
public static function getShareFolder() {
$shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
$shareFolder = \OC\Files\Filesystem::normalizePath($shareFolder);
$shareFolder = Filesystem::normalizePath($shareFolder);
if (!\OC\Files\Filesystem::file_exists($shareFolder)) {
if (!Filesystem::file_exists($shareFolder)) {
$dir = '';
$subdirs = explode('/', $shareFolder);
foreach ($subdirs as $subdir) {
$dir = $dir . '/' . $subdir;
if (!\OC\Files\Filesystem::is_dir($dir)) {
\OC\Files\Filesystem::mkdir($dir);
if (!Filesystem::is_dir($dir)) {
Filesystem::mkdir($dir);
}
}
}