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
This commit is contained in:
parent
cfc52ccc3d
commit
a27db9e4ca
|
@ -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']);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
$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));
|
||||
/**
|
||||
* @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 {
|
||||
$source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
|
||||
$fileOwner = $source['uid_owner'];
|
||||
}
|
||||
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', $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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue