diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php index 8d668c8329f..0bb45731b2b 100644 --- a/apps/files_sharing/admin.php +++ b/apps/files_sharing/admin.php @@ -24,7 +24,7 @@ require_once('../../lib/base.php'); require_once( 'lib_share.php' ); require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ +if (!OC_USER::isLoggedIn()){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index c53059b2ec8..6a3b36b420f 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -72,10 +72,20 @@ class OC_SHARE { public static function unshare($item, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($item, $uid, $_SESSION['user_id']))->fetchAll(); + $query->execute(array($item, $uid, $_SESSION['user_id'])); } } + /** + * Get the source location of the target item + * @return source path + */ + public static function getSource($target) { + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + return $result[0]['source']; + } + /** * Get all items the user is sharing * @return array diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 25824f2779d..cd797e9d0ad 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -20,8 +20,273 @@ * */ -class OC_FILESTORAGE_SHARE { +require_once( 'lib_share.php' ); + +OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datadir'=>'string')); + +/** + * Convert target path to source path and pass the function call to the correct storage provider + */ +class OC_FILESTORAGE_SHARED { + + // TODO uh... I don't know what to do here + public function __construct($parameters) { + + } + + // TODO OC_SHARE::getPermissions() + public function mkdir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->mkdir(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function rmdir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function opendir($path) { + //$source = OC_SHARE::getSource($path); + //if ($source) { + //$storage = OC_FILESYSTEM::getStorage($source); + //return $storage->opendir(OC_FILESYSTEM::getInternalPath($source)); + //} + global $FAKEDIRS; + $FAKEDIRS['shared'] = array(0 => 'test.txt'); + return opendir('fakedir://shared'); + } + + public function is_dir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_dir(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function is_file($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + } + } + public function stat($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->stat(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filetype($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filetype(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filesize($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filesize(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function is_readable($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_readable(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function is_writeable($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_writeable(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function file_exists($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_exists(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function readfile($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->readfile(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filectime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filectime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filemtime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filemtime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function fileatime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fileatime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function file_get_contents($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_get_contents(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function file_put_contents($path, $data) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_put_contents(OC_FILESYSTEM::getInternalPath($source), $data); + } + } + + public function unlink($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->unlink(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + // TODO Update shared item location + public function rename($path1, $path2) { + $source = OC_SHARE::getSource($path1); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->rename(OC_FILESYSTEM::getInternalPath($source), $path2); + } + } + + public function copy($path1, $path2) { + $source = OC_SHARE::getSource($path1); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->copy(OC_FILESYSTEM::getInternalPath($source), $path2); + } + } + + public function fopen($path, $mode) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fopen(OC_FILESYSTEM::getInternalPath($source), $mode); + } + } + + public function toTmpFile($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->toTmpFile(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function fromTmpFile($tmpPath, $path) { + $source = OC_SHARE::getSource($tmpPath); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fromTmpFile(OC_FILESYSTEM::getInternalPath($source), $path); + } + } + + public function fromUploadedFile($tmpPath, $path) { + $source = OC_SHARE::getSource($tmpPath); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fromUploadedFile(OC_FILESYSTEM::getInternalPath($source), $path); + } + } + + public function getMimeType($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->getMimeType(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function delTree($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->delTree(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function find($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->find(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function getTree($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->getTree(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function hash($type, $path, $raw) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->hash($type, OC_FILESYSTEM::getInternalPath($source), $raw); + } + } + + public function free_space($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->free_space(OC_FILESYSTEM::getInternalPath($source)); + } + } + // TODO query all shared files? + public function search($query) { + + } } diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php index 764aee00b49..827b64143c5 100644 --- a/apps/files_sharing/templates/admin.php +++ b/apps/files_sharing/templates/admin.php @@ -2,25 +2,26 @@
| Item | -Shared With | -Link | +Item | +Shared With | +Permissions |
|---|---|---|---|---|---|
| + | - | '>?token= | +|||