Skip to content
Snippets Groups Projects
Commit a27db9e4 authored by Björn Schießle's avatar Björn Schießle
Browse files

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
parent cfc52ccc
Branches
No related tags found
No related merge requests found
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
/** /**
* ownCloud * ownCloud
* *
* @author Michael Gapczynski * @author Bjoern Schiessle, Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com * @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
...@@ -46,7 +47,10 @@ class Shared_Cache extends Cache { ...@@ -46,7 +47,10 @@ class Shared_Cache extends Cache {
* @return \OC\Files\Cache\Cache * @return \OC\Files\Cache\Cache
*/ */
private function getSourceCache($target) { 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'])) { if (isset($source['path']) && isset($source['fileOwner'])) {
\OC\Files\Filesystem::initMountPoints($source['fileOwner']); \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
...@@ -127,28 +131,24 @@ class Shared_Cache extends Cache { ...@@ -127,28 +131,24 @@ class Shared_Cache extends Cache {
* @return array * @return array
*/ */
public function getFolderContents($folder) { public function getFolderContents($folder) {
if ($folder == '') {
$files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS); if ($folder === false) {
foreach ($files as &$file) { $folder = '';
$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); $cache = $this->getSourceCache($folder);
if ($cache) { if ($cache) {
$parent = $this->storage->getFile($folder); $parent = $this->storage->getFile($folder);
$sourceFolderContent = $cache->getFolderContents($this->files[$folder]); $sourceFolderContent = $cache->getFolderContents($this->files[$folder]);
foreach ($sourceFolderContent as $key => $c) { foreach ($sourceFolderContent as $key => $c) {
$sourceFolderContent[$key]['usersPath'] = 'files/Shared/' . $folder . '/' . $c['name']; $sourceFolderContent[$key]['usersPath'] = 'files/' . $folder . '/' . $c['name'];
$sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner']; $sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
$sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner']; $sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
} }
return $sourceFolderContent; return $sourceFolderContent;
} }
}
return false; return false;
} }
...@@ -214,7 +214,7 @@ class Shared_Cache extends Cache { ...@@ -214,7 +214,7 @@ class Shared_Cache extends Cache {
*/ */
public function move($source, $target) { public function move($source, $target) {
if ($cache = $this->getSourceCache($source)) { 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'])) { if ($file && isset($file['path'])) {
$cache->move($this->files[$source], $file['path']); $cache->move($this->files[$source], $file['path']);
} }
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
/** /**
* ownCloud * ownCloud
* *
* @author Michael Gapczynski * @author Bjoern Schiessle, Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com * @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
...@@ -146,24 +147,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { ...@@ -146,24 +147,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
return array(); return array();
} }
public static function getSource($target) { /**
if ($target == '') { * @brief resolve reshares to return the correct source item
return false; * @param array $source
} * @return array source item
$target = '/'.$target; */
$target = rtrim($target, '/'); protected static function resolveReshares($source) {
$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));
}
} else {
$source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
}
if ($source) {
if (isset($source['parent'])) { if (isset($source['parent'])) {
$parent = $source['parent']; $parent = $source['parent'];
while (isset($parent)) { while (isset($parent)) {
...@@ -179,9 +168,29 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { ...@@ -179,9 +168,29 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
} else { } else {
$fileOwner = $source['uid_owner']; $fileOwner = $source['uid_owner'];
} }
if (isset($fileOwner)) {
$source['fileOwner'] = $fileOwner; $source['fileOwner'] = $fileOwner;
} else {
\OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR);
}
return $source; 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', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
}
if ($source) {
return self::resolveReshares($source);
}
\OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::DEBUG); \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::DEBUG);
return false; return false;
} }
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
/** /**
* ownCloud * ownCloud
* *
* @author Michael Gapczynski * @author Bjoern Schiessle, Michael Gapczynski
* @copyright 2011 Michael Gapczynski mtgap@owncloud.com * @copyright 2011 Michael Gapczynski <mtgap@owncloud.com>
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
...@@ -27,15 +28,17 @@ namespace OC\Files\Storage; ...@@ -27,15 +28,17 @@ namespace OC\Files\Storage;
*/ */
class Shared extends \OC\Files\Storage\Common { 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(); private $files = array();
public function __construct($arguments) { public function __construct($arguments) {
$this->sharedFolder = $arguments['sharedFolder']; $this->mountPoint = $arguments['shareTarget'];
$this->type = $arguments['shareType'];
} }
public function getId() { public function getId() {
return 'shared::' . $this->sharedFolder; return 'shared::' . $this->mountPoint;
} }
/** /**
...@@ -48,14 +51,14 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -48,14 +51,14 @@ class Shared extends \OC\Files\Storage\Common {
if (!isset($this->files[$target])) { if (!isset($this->files[$target])) {
// Check for partial files // Check for partial files
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { 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) { if ($source) {
$source['path'] .= '.part'; $source['path'] .= '.part';
// All partial files have delete permission // All partial files have delete permission
$source['permissions'] |= \OCP\PERMISSION_DELETE; $source['permissions'] |= \OCP\PERMISSION_DELETE;
} }
} else { } else {
$source = \OC_Share_Backend_File::getSource($target); $source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getShareType());
} }
$this->files[$target] = $source; $this->files[$target] = $source;
} }
...@@ -119,8 +122,8 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -119,8 +122,8 @@ class Shared extends \OC\Files\Storage\Common {
public function opendir($path) { public function opendir($path) {
if ($path == '' || $path == '/') { if ($path == '' || $path == '/') {
$files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR); $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR);
\OC\Files\Stream\Dir::register('shared', $files); \OC\Files\Stream\Dir::register($this->mountPoint, $files);
return opendir('fakedir://shared'); return opendir('fakedir://' . $this->mountPoint);
} else if ($source = $this->getSourcePath($path)) { } else if ($source = $this->getSourcePath($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->opendir($internalPath); return $storage->opendir($internalPath);
...@@ -180,7 +183,7 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -180,7 +183,7 @@ class Shared extends \OC\Files\Storage\Common {
public function isCreatable($path) { public function isCreatable($path) {
if ($path == '') { if ($path == '') {
return false; return ($this->getPermissions($this->getMountPoint()) & \OCP\PERMISSION_CREATE);
} }
return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE); return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
} }
...@@ -246,7 +249,7 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -246,7 +249,7 @@ class Shared extends \OC\Files\Storage\Common {
$source = $this->getSourcePath($path); $source = $this->getSourcePath($path);
if ($source) { if ($source) {
$info = array( $info = array(
'target' => $this->sharedFolder . $path, 'target' => $this->mountPoint . $path,
'source' => $source, 'source' => $source,
); );
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
...@@ -264,7 +267,7 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -264,7 +267,7 @@ class Shared extends \OC\Files\Storage\Common {
return false; return false;
} }
$info = array( $info = array(
'target' => $this->sharedFolder . $path, 'target' => $this->mountPoint . $path,
'source' => $source, 'source' => $source,
); );
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
...@@ -343,7 +346,7 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -343,7 +346,7 @@ class Shared extends \OC\Files\Storage\Common {
} }
} }
$info = array( $info = array(
'target' => $this->sharedFolder . $path, 'target' => $this->mountPoint . $path,
'source' => $source, 'source' => $source,
'mode' => $mode, 'mode' => $mode,
); );
...@@ -393,14 +396,35 @@ class Shared extends \OC\Files\Storage\Common { ...@@ -393,14 +396,35 @@ class Shared extends \OC\Files\Storage\Common {
} }
public static function setup($options) { public static function setup($options) {
$shares = \OCP\Share::getItemsSharedWith('file');
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user'] if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
|| \OCP\Share::getItemsSharedWith('file') || $shares
) { ) {
$user_dir = $options['user_dir']; foreach ($shares as $share) {
\OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
array('sharedFolder' => '/Shared'), array(
$user_dir . '/Shared/'); '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) { public function hasUpdated($path, $time) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment