Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2016-02-18 11:57:29 +0300
committerBjoern Schiessle <schiessle@owncloud.com>2016-02-18 12:17:00 +0300
commit89851813051a89659bc6a003c127635efb0e0035 (patch)
treea83f9fb43ac26fb742f6b26ebb147af39d12d1ea
parentac1c3d27b762d3abd438b2b242edc992cd6647b7 (diff)
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
-rw-r--r--apps/files_sharing/lib/helper.php58
1 files changed, 43 insertions, 15 deletions
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index cffdc8887ec..e857974ae74 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -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);
}
}
}