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:
parent
ac1c3d27b7
commit
8985181305
|
@ -29,7 +29,9 @@
|
||||||
namespace OCA\Files_Sharing;
|
namespace OCA\Files_Sharing;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
|
use OC\Files\View;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\User;
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
|
|
||||||
|
@ -78,7 +80,7 @@ class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
|
$path = Filesystem::getPath($linkItem['file_source']);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
\OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
|
||||||
\OC_Response::setStatus(404);
|
\OC_Response::setStatus(404);
|
||||||
|
@ -103,8 +105,8 @@ class Helper {
|
||||||
|
|
||||||
$basePath = $path;
|
$basePath = $path;
|
||||||
|
|
||||||
if ($relativePath !== null && \OC\Files\Filesystem::isReadable($basePath . $relativePath)) {
|
if ($relativePath !== null && Filesystem::isReadable($basePath . $relativePath)) {
|
||||||
$path .= \OC\Files\Filesystem::normalizePath($relativePath);
|
$path .= Filesystem::normalizePath($relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -168,11 +170,11 @@ class Helper {
|
||||||
|
|
||||||
public static function getSharesFromItem($target) {
|
public static function getSharesFromItem($target) {
|
||||||
$result = array();
|
$result = array();
|
||||||
$owner = \OC\Files\Filesystem::getOwner($target);
|
$owner = Filesystem::getOwner($target);
|
||||||
\OC\Files\Filesystem::initMountPoints($owner);
|
Filesystem::initMountPoints($owner);
|
||||||
$info = \OC\Files\Filesystem::getFileInfo($target);
|
$info = Filesystem::getFileInfo($target);
|
||||||
$ownerView = new \OC\Files\View('/'.$owner.'/files');
|
$ownerView = new View('/'.$owner.'/files');
|
||||||
if ( $owner != \OCP\User::getUser() ) {
|
if ( $owner != User::getUser() ) {
|
||||||
$path = $ownerView->getPath($info['fileid']);
|
$path = $ownerView->getPath($info['fileid']);
|
||||||
} else {
|
} else {
|
||||||
$path = $target;
|
$path = $target;
|
||||||
|
@ -205,8 +207,34 @@ class Helper {
|
||||||
return $result;
|
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) {
|
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 string $path
|
||||||
* @param array $excludeList
|
* @param array $excludeList
|
||||||
* @param \OC\Files\View $view
|
* @param View $view
|
||||||
* @return string $path
|
* @return string $path
|
||||||
*/
|
*/
|
||||||
public static function generateUniqueTarget($path, $excludeList, $view) {
|
public static function generateUniqueTarget($path, $excludeList, $view) {
|
||||||
|
@ -244,7 +272,7 @@ class Helper {
|
||||||
$dir = $pathinfo['dirname'];
|
$dir = $pathinfo['dirname'];
|
||||||
$i = 2;
|
$i = 2;
|
||||||
while ($view->file_exists($path) || in_array($path, $excludeList)) {
|
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++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,15 +306,15 @@ class Helper {
|
||||||
*/
|
*/
|
||||||
public static function getShareFolder() {
|
public static function getShareFolder() {
|
||||||
$shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
|
$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 = '';
|
$dir = '';
|
||||||
$subdirs = explode('/', $shareFolder);
|
$subdirs = explode('/', $shareFolder);
|
||||||
foreach ($subdirs as $subdir) {
|
foreach ($subdirs as $subdir) {
|
||||||
$dir = $dir . '/' . $subdir;
|
$dir = $dir . '/' . $subdir;
|
||||||
if (!\OC\Files\Filesystem::is_dir($dir)) {
|
if (!Filesystem::is_dir($dir)) {
|
||||||
\OC\Files\Filesystem::mkdir($dir);
|
Filesystem::mkdir($dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue