aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-02 12:04:51 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:54:24 +0200
commita27db9e4cadb9b5ee26f7b17d3a5997b07639489 (patch)
treef1f312d96caf3bac49b22ef76fa3decd71a4f8d7
parentcfc52ccc3d3e7e233912adc58bdc95618d941a30 (diff)
downloadnextcloud-server-a27db9e4cadb9b5ee26f7b17d3a5997b07639489.tar.gz
nextcloud-server-a27db9e4cadb9b5ee26f7b17d3a5997b07639489.zip
first steps to remove the shared folder:
- mount shares to the root folder instead of "Shared/" - navigate in shared folder and sub-folders - show previews - show correct file permissions - download/edit files
-rw-r--r--apps/files_sharing/lib/cache.php46
-rw-r--r--apps/files_sharing/lib/share/file.php73
-rw-r--r--apps/files_sharing/lib/sharedstorage.php60
3 files changed, 106 insertions, 73 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index eeb62c3cce2..c509ec24576 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -2,8 +2,9 @@
/**
* ownCloud
*
- * @author Michael Gapczynski
- * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+ * @author Bjoern Schiessle, Michael Gapczynski
+ * @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
+ * 2014 Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -46,7 +47,10 @@ class Shared_Cache extends Cache {
* @return \OC\Files\Cache\Cache
*/
private function getSourceCache($target) {
- $source = \OC_Share_Backend_File::getSource($target);
+ if ($target === false) {
+ $target = '';
+ }
+ $source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getShareType());
if (isset($source['path']) && isset($source['fileOwner'])) {
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
@@ -127,28 +131,24 @@ class Shared_Cache extends Cache {
* @return array
*/
public function getFolderContents($folder) {
- if ($folder == '') {
- $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS);
- foreach ($files as &$file) {
- $file['mimetype'] = $this->getMimetype($file['mimetype']);
- $file['mimepart'] = $this->getMimetype($file['mimepart']);
- $file['usersPath'] = 'files/Shared/' . ltrim($file['path'], '/');
- }
- return $files;
- } else {
- $cache = $this->getSourceCache($folder);
- if ($cache) {
- $parent = $this->storage->getFile($folder);
- $sourceFolderContent = $cache->getFolderContents($this->files[$folder]);
- foreach ($sourceFolderContent as $key => $c) {
- $sourceFolderContent[$key]['usersPath'] = 'files/Shared/' . $folder . '/' . $c['name'];
- $sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
- $sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
- }
- return $sourceFolderContent;
+ if ($folder === false) {
+ $folder = '';
+ }
+
+ $cache = $this->getSourceCache($folder);
+ if ($cache) {
+ $parent = $this->storage->getFile($folder);
+ $sourceFolderContent = $cache->getFolderContents($this->files[$folder]);
+ foreach ($sourceFolderContent as $key => $c) {
+ $sourceFolderContent[$key]['usersPath'] = 'files/' . $folder . '/' . $c['name'];
+ $sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
+ $sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
}
+
+ return $sourceFolderContent;
}
+
return false;
}
@@ -214,7 +214,7 @@ class Shared_Cache extends Cache {
*/
public function move($source, $target) {
if ($cache = $this->getSourceCache($source)) {
- $file = \OC_Share_Backend_File::getSource($target);
+ $file = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getShareType());
if ($file && isset($file['path'])) {
$cache->move($this->files[$source], $file['path']);
}
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index 5e00050fe1e..b5196ab6fac 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -2,8 +2,9 @@
/**
* ownCloud
*
-* @author Michael Gapczynski
-* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+* @author Bjoern Schiessle, Michael Gapczynski
+* @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
+ * 2014 Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -146,42 +147,50 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
return array();
}
- public static function getSource($target) {
- if ($target == '') {
- return false;
+ /**
+ * @brief resolve reshares to return the correct source item
+ * @param array $source
+ * @return array source item
+ */
+ protected static function resolveReshares($source) {
+ if (isset($source['parent'])) {
+ $parent = $source['parent'];
+ while (isset($parent)) {
+ $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
+ $item = $query->execute(array($parent))->fetchRow();
+ if (isset($item['parent'])) {
+ $parent = $item['parent'];
+ } else {
+ $fileOwner = $item['uid_owner'];
+ break;
+ }
+ }
+ } else {
+ $fileOwner = $source['uid_owner'];
}
- $target = '/'.$target;
- $target = rtrim($target, '/');
- $pos = strpos($target, '/', 1);
- // Get shared folder name
- if ($pos !== false) {
- $folder = substr($target, 0, $pos);
- $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- if ($source) {
- $source['path'] = $source['path'].substr($target, strlen($folder));
+ if (isset($fileOwner)) {
+ $source['fileOwner'] = $fileOwner;
+ } else {
+ \OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR);
+ }
+
+ return $source;
+ }
+
+ public static function getSource($target, $mountPoint, $itemType) {
+
+ if ($itemType === 'folder') {
+ $source = \OCP\Share::getItemSharedWith('folder', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source && $target !== '') {
+ $source['path'] = $source['path'].'/'.$target;
}
} else {
- $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ $source = \OCP\Share::getItemSharedWith('file', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
}
if ($source) {
- if (isset($source['parent'])) {
- $parent = $source['parent'];
- while (isset($parent)) {
- $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
- $item = $query->execute(array($parent))->fetchRow();
- if (isset($item['parent'])) {
- $parent = $item['parent'];
- } else {
- $fileOwner = $item['uid_owner'];
- break;
- }
- }
- } else {
- $fileOwner = $source['uid_owner'];
- }
- $source['fileOwner'] = $fileOwner;
- return $source;
+ return self::resolveReshares($source);
}
+
\OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::DEBUG);
return false;
}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index b922654e5ec..25a05a0d1f2 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -2,8 +2,9 @@
/**
* ownCloud
*
- * @author Michael Gapczynski
- * @copyright 2011 Michael Gapczynski mtgap@owncloud.com
+ * @author Bjoern Schiessle, Michael Gapczynski
+ * @copyright 2011 Michael Gapczynski <mtgap@owncloud.com>
+ * 2014 Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -27,15 +28,17 @@ namespace OC\Files\Storage;
*/
class Shared extends \OC\Files\Storage\Common {
- private $sharedFolder;
+ private $mountPoint; // mount point relative to data/user/files
+ private $type; // can be "file" or "folder"
private $files = array();
public function __construct($arguments) {
- $this->sharedFolder = $arguments['sharedFolder'];
+ $this->mountPoint = $arguments['shareTarget'];
+ $this->type = $arguments['shareType'];
}
public function getId() {
- return 'shared::' . $this->sharedFolder;
+ return 'shared::' . $this->mountPoint;
}
/**
@@ -48,14 +51,14 @@ class Shared extends \OC\Files\Storage\Common {
if (!isset($this->files[$target])) {
// Check for partial files
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
- $source = \OC_Share_Backend_File::getSource(substr($target, 0, -5));
+ $source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getMountPoint(), $this->getShareType());
if ($source) {
$source['path'] .= '.part';
// All partial files have delete permission
$source['permissions'] |= \OCP\PERMISSION_DELETE;
}
} else {
- $source = \OC_Share_Backend_File::getSource($target);
+ $source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getShareType());
}
$this->files[$target] = $source;
}
@@ -119,8 +122,8 @@ class Shared extends \OC\Files\Storage\Common {
public function opendir($path) {
if ($path == '' || $path == '/') {
$files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR);
- \OC\Files\Stream\Dir::register('shared', $files);
- return opendir('fakedir://shared');
+ \OC\Files\Stream\Dir::register($this->mountPoint, $files);
+ return opendir('fakedir://' . $this->mountPoint);
} else if ($source = $this->getSourcePath($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->opendir($internalPath);
@@ -180,7 +183,7 @@ class Shared extends \OC\Files\Storage\Common {
public function isCreatable($path) {
if ($path == '') {
- return false;
+ return ($this->getPermissions($this->getMountPoint()) & \OCP\PERMISSION_CREATE);
}
return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
}
@@ -246,7 +249,7 @@ class Shared extends \OC\Files\Storage\Common {
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
- 'target' => $this->sharedFolder . $path,
+ 'target' => $this->mountPoint . $path,
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
@@ -264,7 +267,7 @@ class Shared extends \OC\Files\Storage\Common {
return false;
}
$info = array(
- 'target' => $this->sharedFolder . $path,
+ 'target' => $this->mountPoint . $path,
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
@@ -343,7 +346,7 @@ class Shared extends \OC\Files\Storage\Common {
}
}
$info = array(
- 'target' => $this->sharedFolder . $path,
+ 'target' => $this->mountPoint . $path,
'source' => $source,
'mode' => $mode,
);
@@ -393,16 +396,37 @@ class Shared extends \OC\Files\Storage\Common {
}
public static function setup($options) {
+ $shares = \OCP\Share::getItemsSharedWith('file');
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
- || \OCP\Share::getItemsSharedWith('file')
+ || $shares
) {
- $user_dir = $options['user_dir'];
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
- array('sharedFolder' => '/Shared'),
- $user_dir . '/Shared/');
+ foreach ($shares as $share) {
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
+ array(
+ 'shareTarget' => $share['file_target'],
+ 'shareType' => $share['item_type'],
+ ),
+ $options['user_dir'] . '/' . $share['file_target']);
+ }
}
}
+ /**
+ * @brief return mount point of share, relative to data/user/files
+ * @return string
+ */
+ public function getMountPoint() {
+ return ltrim($this->mountPoint, '/');
+ }
+
+ /**
+ * @brief return share type, can be "file" or "folder"
+ * @return string
+ */
+ public function getShareType() {
+ return $this->type;
+ }
+
public function hasUpdated($path, $time) {
if ($path == '') {
return false;