diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-19 22:29:01 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-19 22:29:01 -0400 |
commit | 82d81e8d39ce69211ec6b29fe3f803c57714b8dd (patch) | |
tree | 09dbd675480a02fd626f6634e083f3d6a01b4404 /apps/files_sharing | |
parent | f893d21660695d1d1cd594c102e2bcba6919dee3 (diff) | |
parent | 5eca531f99f9615d1a09bbb0b03dda2063901aa7 (diff) | |
download | nextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.tar.gz nextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.zip |
Merge branch 'share_api'
Conflicts:
apps/contacts/lib/vcard.php
apps/files/index.php
lib/files.php
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/appinfo/app.php | 6 | ||||
-rw-r--r-- | apps/files_sharing/css/sharing.css | 16 | ||||
-rw-r--r-- | apps/files_sharing/lib/share/file.php | 91 | ||||
-rw-r--r-- | apps/files_sharing/lib/share/folder.php | 61 | ||||
-rw-r--r-- | apps/files_sharing/sharedstorage.php | 509 | ||||
-rwxr-xr-x | apps/files_sharing/templates/get.php | 11 |
6 files changed, 396 insertions, 298 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index bbb753d5e69..7495a5bbe6c 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,6 +1,8 @@ <?php OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php"; +OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php"; +OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php'; OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/sharedstorage.php"; OCP\App::registerAdmin('files_sharing', 'settings'); @@ -17,8 +19,10 @@ OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFrom $dir = isset($_GET['dir']) ? $_GET['dir'] : '/'; if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') { - OCP\Util::addscript("files_sharing", "share"); + OCP\Util::addScript('core', 'share'); } OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min"); OCP\Util::addStyle( 'files_sharing', 'sharing' ); OCP\Util::addStyle("3rdparty", "chosen/chosen"); +OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); +OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); diff --git a/apps/files_sharing/css/sharing.css b/apps/files_sharing/css/sharing.css index d4fcf79ee98..a683a24a116 100644 --- a/apps/files_sharing/css/sharing.css +++ b/apps/files_sharing/css/sharing.css @@ -2,14 +2,16 @@ This file is licensed under the Affero General Public License version 3 or later. See the COPYING-README file. */ -#dropdown { display:block; position:absolute; z-index:100; width:16em; right:0; margin-right:7em; background:#eee; padding:1em; +#dropdown { display:block; position:absolute; z-index:500; width:16em; right:0; margin-right:7em; background:#eee; padding:1em; -moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777; -moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em; -moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; } -#sharedWithList { padding:0.5em; list-style-type: none; } -#privateLink { border-top:1px solid #ddd; padding-top:0.5em; } -a.unshare { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; opacity:.5; } +#shareWithList { padding:0.5em; list-style-type: none; } +#shareWithList li { padding-top:0.1em; } +#dropdown label { font-weight:normal; } +#dropdown input[type="checkbox"] { margin:0 0.2em 0 0.5em; } +a.showCruds { display:inline; opacity:.5; } +a.showCruds:hover { opacity:1; } +a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; } a.unshare:hover { opacity:1; } -#share_with { width: 16em; } -#privateLink label, .edit { font-weight:normal; } -#share_with_chzn { display: block; } +#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
\ No newline at end of file diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php new file mode 100644 index 00000000000..ae6315600f8 --- /dev/null +++ b/apps/files_sharing/lib/share/file.php @@ -0,0 +1,91 @@ +<?php +/** +* ownCloud +* +* @author Michael Gapczynski +* @copyright 2012 Michael Gapczynski mtgap@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 +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + +class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { + + const FORMAT_SHARED_STORAGE = 0; + const FORMAT_FILE_APP = 1; + const FORMAT_FILE_APP_ROOT = 2; + const FORMAT_OPENDIR = 3; + + public function isValidSource($item, $uid) { + if (OC_Filesystem::file_exists($item)) { + return true; + } + return false; + } + + public function getFilePath($item, $uid) { + return $item; + } + + public function generateTarget($item, $uid, $exclude = null) { + // TODO Make sure target path doesn't exist already + return $item; + } + + public function formatItems($items, $format, $parameters = null) { + if ($format == self::FORMAT_SHARED_STORAGE) { + // Only 1 item should come through for this format call + return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); + } else if ($format == self::FORMAT_FILE_APP) { + $files = array(); + foreach ($items as $item) { + $file = array(); + $file['path'] = $item['file_target']; + $file['name'] = basename($item['file_target']); + $file['ctime'] = $item['ctime']; + $file['mtime'] = $item['mtime']; + $file['mimetype'] = $item['mimetype']; + $file['size'] = $item['size']; + $file['encrypted'] = $item['encrypted']; + $file['versioned'] = $item['versioned']; + $file['directory'] = $parameters['folder']; + $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $file['permissions'] = $item['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE; + } + $files[] = $file; + } + return $files; + } else if ($format == self::FORMAT_FILE_APP_ROOT) { + $mtime = 0; + $size = 0; + foreach ($items as $item) { + if ($item['mtime'] > $mtime) { + $mtime = $item['mtime']; + } + $size += $item['size']; + } + return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ)); + } else if ($format == self::FORMAT_OPENDIR) { + $files = array(); + foreach ($items as $item) { + $files[] = basename($item['file_target']); + } + return $files; + } + return array(); + } + +}
\ No newline at end of file diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php new file mode 100644 index 00000000000..b6db96614fd --- /dev/null +++ b/apps/files_sharing/lib/share/folder.php @@ -0,0 +1,61 @@ +<?php +/** +* ownCloud +* +* @author Michael Gapczynski +* @copyright 2012 Michael Gapczynski mtgap@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 +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + +class OC_Share_Backend_Folder extends OC_Share_Backend_File { + + public function formatItems($items, $format, $parameters = null) { + if ($format == self::FORMAT_SHARED_STORAGE) { + // Only 1 item should come through for this format call + return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); + } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) { + // Only 1 item should come through for this format call + $folder = $items[key($items)]; + if (isset($parameters['mimetype_filter'])) { + $mimetype_filter = $parameters['mimetype_filter']; + } else { + $mimetype_filter = ''; + } + $path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target'])); + $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter); + foreach ($files as &$file) { + $file['directory'] = $parameters['folder']; + $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $file['permissions'] = $folder['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE; + } + } + return $files; + } + return array(); + } + + public function getChildren($itemSource) { + $files = OC_FileCache::getFolderContent($itemSource); + $sources = array(); + foreach ($files as $file) { + $sources[] = $file['path']; + } + return $sources; + } + +}
\ No newline at end of file diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 05df275ca9f..582c9c66172 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -3,7 +3,7 @@ * ownCloud * * @author Michael Gapczynski - * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com + * @copyright 2011 Michael Gapczynski mtgap@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 @@ -20,213 +20,217 @@ * */ -require_once( 'lib_share.php' ); - /** * Convert target path to source path and pass the function call to the correct storage provider */ class OC_Filestorage_Shared extends OC_Filestorage_Common { - private $datadir; - private $sourcePaths = array(); + private $sharedFolder; + private $files = array(); public function __construct($arguments) { - $this->datadir = $arguments['datadir']; - $this->datadir .= "/"; + $this->sharedFolder = $arguments['sharedFolder']; } - - public function getInternalPath($path) { + + /** + * @brief Get the source file path and the permissions granted for a shared file + * @param string Shared target file path + * @return Returns array with the keys path and permissions or false if not found + */ + private function getFile($target) { + $target = '/'.$target; + $target = rtrim($target, '/'); + if (isset($this->files[$target])) { + return $this->files[$target]; + } else { + $pos = strpos($target, '/', 1); + // Get shared folder name + if ($pos !== false) { + $folder = substr($target, 0, $pos); + if (isset($this->files[$folder])) { + $file = $this->files[$folder]; + } else { + $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE); + } + if ($file) { + $this->files[$target]['path'] = $file['path'].substr($target, strlen($folder)); + $this->files[$target]['permissions'] = $file['permissions']; + return $this->files[$target]; + } + } else { + $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE); + if ($file) { + $this->files[$target] = $file; + return $this->files[$target]; + } + } + OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR); + return false; + } + } + + /** + * @brief Get the source file path for a shared file + * @param string Shared target file path + * @return Returns source file path or false if not found + */ + private function getSourcePath($target) { + $file = $this->getFile($target); + if (isset($file['path'])) { + return $file['path']; + } + return false; + } + + /** + * @brief Get the permissions granted for a shared file + * @param string Shared target file path + * @return Returns CRUDS permissions granted or false if not found + */ + private function getPermissions($target) { + $file = $this->getFile($target); + if (isset($file['permissions'])) { + return $file['permissions']; + } + return false; + } + + /** + * @brief Get the internal path to pass to the storage filesystem call + * @param string Source file path + * @return Source file path with mount point stripped out + */ + private function getInternalPath($path) { $mountPoint = OC_Filesystem::getMountPoint($path); $internalPath = substr($path, strlen($mountPoint)); return $internalPath; } - public function getSource($target) { - $target = $this->datadir.$target; - if (array_key_exists($target, $this->sourcePaths)) { - return $this->sourcePaths[$target]; - } else { - $source = OC_Share::getSource($target); - $this->sourcePaths[$target] = $source; - return $source; - } - } - public function mkdir($path) { - if ($path == "" || $path == "/" || !$this->is_writable($path)) { + if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) { return false; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->mkdir($this->getInternalPath($source)); - } + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->mkdir($this->getInternalPath($source)); } + return false; } public function rmdir($path) { - // The folder will be removed from the database, but won't be deleted from the owner's filesystem - OC_Share::unshareFromMySelf($this->datadir.$path); + if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->rmdir($this->getInternalPath($source)); + } + return false; } public function opendir($path) { - if ($path == "" || $path == "/") { - $path = $this->datadir.$path; - $sharedItems = OC_Share::getItemsInFolder($path); - $files = array(); - foreach ($sharedItems as $item) { - // If item is in the root of the shared storage provider and the item exists add it to the fakedirs - if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) { - $files[] = basename($item['target']); - } - } - OC_FakeDirStream::$dirs['shared'.$path] = $files; - return opendir('fakedir://shared'.$path); - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - $dh = $storage->opendir($this->getInternalPath($source)); - $modifiedItems = OC_Share::getItemsInFolder($source); - if ($modifiedItems && $dh) { - $sources = array(); - $targets = array(); - // Remove any duplicate or trailing '/' - $path = preg_replace('{(/)\1+}', "/", $path); - $targetFolder = rtrim($this->datadir.$path, "/"); - foreach ($modifiedItems as $item) { - // If the item is in the current directory and the item exists add it to the arrays - if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) { - // If the item was unshared from self, add it it to the arrays - if ($item['permissions'] == OC_Share::UNSHARED) { - $sources[] = basename($item['source']); - $targets[] = ""; - } else { - $sources[] = basename($item['source']); - $targets[] = basename($item['target']); - } - } - } - // Don't waste time if there aren't any modified items in the current directory - if (empty($sources)) { - return $dh; - } else { - global $FAKEDIRS; - $files = array(); - while (($filename = readdir($dh)) !== false) { - if ($filename != "." && $filename != "..") { - // If the file isn't in the sources array it isn't modified and can be added as is - if (!in_array($filename, $sources)) { - $files[] = $filename; - // The file has a different name than the source and is added to the fakedirs - } else { - $target = $targets[array_search($filename, $sources)]; - // Don't add the file if it was unshared from self by the user - if ($target != "") { - $files[] = $target; - } - } - } - } - $FAKEDIRS['shared'] = $files; - return opendir('fakedir://shared'); - } - } else { - return $dh; - } - } + if ($path == '' || $path == '/') { + $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR); + OC_FakeDirStream::$dirs['shared'] = $files; + return opendir('fakedir://shared'); + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->opendir($this->getInternalPath($source)); } + return false; } - + public function is_dir($path) { - if ($path == "" || $path == "/") { + if ($path == '' || $path == '/') { return true; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->is_dir($this->getInternalPath($source)); - } + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->is_dir($this->getInternalPath($source)); } + return false; } - + public function is_file($path) { - $source = $this->getSource($path); - if ($source) { + if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->is_file($this->getInternalPath($source)); } + return false; } - - // TODO fill in other components of array + public function stat($path) { - if ($path == "" || $path == "/") { - $stat["size"] = $this->filesize($path); - $stat["mtime"] = $this->filemtime($path); - $stat["ctime"] = $this->filectime($path); + if ($path == '' || $path == '/') { + $stat['size'] = $this->filesize($path); + $stat['mtime'] = $this->filemtime($path); + $stat['ctime'] = $this->filectime($path); return $stat; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->stat($this->getInternalPath($source)); - } + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->stat($this->getInternalPath($source)); } + return false; } - + public function filetype($path) { - if ($path == "" || $path == "/") { - return "dir"; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->filetype($this->getInternalPath($source)); - } + if ($path == '' || $path == '/') { + return 'dir'; + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->filetype($this->getInternalPath($source)); } - + return false; } - + public function filesize($path) { - if ($path == "" || $path == "/" || $this->is_dir($path)) { + if ($path == '' || $path == '/' || $this->is_dir($path)) { return 0; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->filesize($this->getInternalPath($source)); - } + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->filesize($this->getInternalPath($source)); } + return false; } - public function is_readable($path) { - return true; + public function isCreatable($path) { + if ($path == '') { + return false; + } + return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE); } - - public function is_writable($path) { - if($path == "" || $path == "/"){ + + public function isReadable($path) { + return $this->file_exists($path); + } + + public function isUpdatable($path) { + if ($path == '') { return false; - }elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) { - return true; - } else { + } + return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE); + } + + public function isDeletable($path) { + if ($path == '') { return false; } + return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE); } - + + public function isSharable($path) { + if ($path == '') { + return false; + } + return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE); + } + public function file_exists($path) { - if ($path == "" || $path == "/") { + if ($path == '' || $path == '/') { return true; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->file_exists($this->getInternalPath($source)); - } + } else if ($source = $this->getSourcePath($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->file_exists($this->getInternalPath($source)); } + return false; } public function filectime($path) { - if ($path == "" || $path == "/") { + if ($path == '' || $path == '/') { $ctime = 0; if ($dh = $this->opendir($path)) { while (($filename = readdir($dh)) !== false) { @@ -238,7 +242,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } return $ctime; } else { - $source = $this->getSource($path); + $source = $this->getSourcePath($path); if ($source) { $storage = OC_Filesystem::getStorage($source); return $storage->filectime($this->getInternalPath($source)); @@ -247,7 +251,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function filemtime($path) { - if ($path == "" || $path == "/") { + if ($path == '' || $path == '/') { $mtime = 0; if ($dh = $this->opendir($path)) { while (($filename = readdir($dh)) !== false) { @@ -259,7 +263,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } return $mtime; } else { - $source = $this->getSource($path); + $source = $this->getSourcePath($path); if ($source) { $storage = OC_Filesystem::getStorage($source); return $storage->filemtime($this->getInternalPath($source)); @@ -268,10 +272,10 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function file_get_contents($path) { - $source = $this->getSource($path); + $source = $this->getSourcePath($path); if ($source) { $info = array( - 'target' => $this->datadir.$path, + 'target' => $this->sharedFolder.$path, 'source' => $source, ); OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info); @@ -281,92 +285,66 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function file_put_contents($path, $data) { - if ($this->is_writable($path)) { - $source = $this->getSource($path); - if ($source) { - $info = array( - 'target' => $this->datadir.$path, - 'source' => $source, - ); - OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info); - $storage = OC_Filesystem::getStorage($source); - $result = $storage->file_put_contents($this->getInternalPath($source), $data); - return $result; + if ($source = $this->getSourcePath($path)) { + // Check if permission is granted + if (($this->file_exists($path) && !$this->isUpdatable($path)) || ($this->is_dir($path) && !$this->isCreatable($path))) { + return false; } + $info = array( + 'target' => $this->sharedFolder.$path, + 'source' => $source, + ); + OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info); + $storage = OC_Filesystem::getStorage($source); + $result = $storage->file_put_contents($this->getInternalPath($source), $data); + return $result; } + return false; } public function unlink($path) { - // The item will be removed from the database, but won't be touched on the owner's filesystem - $target = $this->datadir.$path; - // Check if the item is inside a shared folder - if (OC_Share::getParentFolders($target)) { - // If entry for item already exists - if (OC_Share::getItem($target)) { - OC_Share::unshareFromMySelf($target, false); - } else { - OC_Share::pullOutOfFolder($target, $target); - OC_Share::unshareFromMySelf($target, false); - } - // Delete the database entry - } else { - OC_Share::unshareFromMySelf($target); + // Delete the file if DELETE permission is granted + if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) { + $storage = OC_Filesystem::getStorage($source); + return $storage->unlink($this->getInternalPath($source)); } - return true; + return false; } public function rename($path1, $path2) { - $oldTarget = $this->datadir.$path1; - $newTarget = $this->datadir.$path2; - // Check if the item is inside a shared folder - if ($folders = OC_Share::getParentFolders($oldTarget)) { - $root1 = substr($path1, 0, strpos($path1, "/")); - $root2 = substr($path1, 0, strpos($path2, "/")); - // Prevent items from being moved into different shared folders until versioning (cut and paste) and prevent items going into 'Shared' - if ($root1 !== $root2) { - return false; - // Check if both paths have write permission - } else if ($this->is_writable($path1) && $this->is_writable($path2)) { - $oldSource = $this->getSource($path1); - $newSource = $folders['source'].substr($newTarget, strlen($folders['target'])); - if ($oldSource) { - $storage = OC_Filesystem::getStorage($oldSource); + if ($oldSource = $this->getSourcePath($path1)) { + $root1 = substr($path1, 0, strpos($path1, '/')); + $root2 = substr($path2, 0, strpos($path2, '/')); + // Moving/renaming is only allowed within the same shared folder + if ($root1 == $root2) { + $storage = OC_Filesystem::getStorage($oldSource); + $newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2; + if (dirname($path1) == dirname($path2)) { + // Rename the file if UPDATE permission is granted + if ($this->isUpdatable($path1)) { + return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource)); + } + // Move the file if DELETE and CREATE permissions are granted + } else if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) { return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource)); } - // If the user doesn't have write permission, items can only be renamed and not moved - } else if (dirname($path1) !== dirname($path2)) { - return false; - // The item will be renamed in the database, but won't be touched on the owner's filesystem - } else { - OC_Share::pullOutOfFolder($oldTarget, $newTarget); - // If this is a folder being renamed, call setTarget in case there are any database entries inside the folder - if (self::is_dir($path1)) { - OC_Share::setTarget($oldTarget, $newTarget); - } } - } else { - OC_Share::setTarget($oldTarget, $newTarget); } - return true; + return false; } public function copy($path1, $path2) { - if ($path2 == "" || $path2 == "/") { - // TODO Construct new shared item or should this not be allowed? - } else { - if ($this->is_writable($path2)) { - $tmpFile = $this->toTmpFile($path1); - $result = $this->fromTmpFile($tmpFile, $path2); - return $result; - } else { - return false; - } + // Copy the file if CREATE permission is granted + if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) { + $source = $this->fopen($path1, 'r'); + $target = $this->fopen($path2, 'w'); + return OC_Helper::streamCopy($source, $target); } + return true; } - + public function fopen($path, $mode) { - $source = $this->getSource($path); - if ($source) { + if ($source = $this->getSourcePath($path)) { switch ($mode) { case 'r+': case 'rb+': @@ -382,12 +360,12 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { case 'xb': case 'a': case 'ab': - if (!$this->is_writable($path)) { + if (!$this->isUpdatable($path)) { return false; } } $info = array( - 'target' => $this->datadir.$path, + 'target' => $this->sharedFolder.$path, 'source' => $source, 'mode' => $mode, ); @@ -395,95 +373,46 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { $storage = OC_Filesystem::getStorage($source); return $storage->fopen($this->getInternalPath($source), $mode); } + return false; } - - public function toTmpFile($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->toTmpFile($this->getInternalPath($source)); - } - } - - public function fromTmpFile($tmpFile, $path) { - if ($this->is_writable($path)) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - $result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source)); - return $result; - } - } else { - return false; - } - } - + public function getMimeType($path) { - if ($path == "" || $path == "/") { + if ($path == '' || $path == '/') { return 'httpd/unix-directory'; } - $source = $this->getSource($path); - if ($source) { + if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->getMimeType($this->getInternalPath($source)); } + return false; } - - public function hash($type, $path, $raw = false) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->hash($type, $this->getInternalPath($source), $raw); - } - } - + public function free_space($path) { - $source = $this->getSource($path); + $source = $this->getSourcePath($path); if ($source) { $storage = OC_Filesystem::getStorage($source); return $storage->free_space($this->getInternalPath($source)); } } - - public function search($query) { - return $this->searchInDir($query); - } - - protected function searchInDir($query, $path = "") { - $files = array(); - if ($dh = $this->opendir($path)) { - while (($filename = readdir($dh)) !== false) { - if ($filename != "." && $filename != "..") { - if (strstr(strtolower($filename), strtolower($query))) { - $files[] = $path."/".$filename; - } - if ($this->is_dir($path."/".$filename)) { - $files = array_merge($files, $this->searchInDir($query, $path."/".$filename)); - } - } - } - } - return $files; - } public function getLocalFile($path) { - $source = $this->getSource($path); - if ($source) { + if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->getLocalFile($this->getInternalPath($source)); } + return false; } - public function touch($path, $mtime=null){ - $source = $this->getSource($path); - if ($source) { + public function touch($path, $mtime = null) { + if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); - return $storage->touch($this->getInternalPath($source),$mtime); + return $storage->touch($this->getInternalPath($source), $mtime); } + return false; } public static function setup($options) { $user_dir = $options['user_dir']; - OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => $user_dir.'/Shared'), $user_dir.'/Shared/'); + OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/'); } /** @@ -493,6 +422,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { */ public function hasUpdated($path,$time){ //TODO - return $this->filemtime($path)>$time; + return false; } } diff --git a/apps/files_sharing/templates/get.php b/apps/files_sharing/templates/get.php new file mode 100755 index 00000000000..57275f07a3d --- /dev/null +++ b/apps/files_sharing/templates/get.php @@ -0,0 +1,11 @@ +<table> + <thead> + <tr> + <th id="headerSize"><?php echo $l->t( 'Size' ); ?></th> + <th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete all')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th> + </tr> + </thead> + <tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>"> + <?php echo($_['fileList']); ?> + </tbody> +</table>
\ No newline at end of file |