summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/cache.php7
-rw-r--r--apps/files_sharing/lib/sharedmount.php161
-rw-r--r--apps/files_sharing/lib/sharedstorage.php230
3 files changed, 242 insertions, 156 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index f6c42e930d1..b2594aa0b4d 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -94,6 +94,11 @@ class Shared_Cache extends Cache {
$data['is_share_mount_point'] = true;
}
$data['uid_owner'] = $this->storage->getOwner($file);
+ if (isset($data['permissions'])) {
+ $data['permissions'] = $data['permissions'] & $this->storage->getPermissions('');
+ } else {
+ $data['permissions'] = $this->storage->getPermissions('');
+ }
return $data;
}
} else {
@@ -130,6 +135,7 @@ class Shared_Cache extends Cache {
$data['name'] = basename($this->storage->getMountPoint());
$data['is_share_mount_point'] = true;
}
+ $data['permissions'] = $data['permissions'] & $this->storage->getPermissions('');
return $data;
}
return false;
@@ -157,6 +163,7 @@ class Shared_Cache extends Cache {
$sourceFolderContent[$key]['path'] = $dir . $c['name'];
$sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
$sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
+ $sourceFolderContent[$key]['permissions'] = $sourceFolderContent[$key]['permissions'] & $this->storage->getPermissions('');
}
return $sourceFolderContent;
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
new file mode 100644
index 00000000000..8d0ecbc6789
--- /dev/null
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Sharing;
+
+use OC\Files\Filesystem;
+use OC\Files\Mount\Mount;
+use OC\Files\Mount\MoveableMount;
+use OC\Files\Storage\Shared;
+
+/**
+ * Shared mount points can be moved by the user
+ */
+class SharedMount extends Mount implements MoveableMount {
+ /**
+ * @var \OC\Files\Storage\Shared $storage
+ */
+ protected $storage = null;
+
+ public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
+ // first update the mount point before creating the parent
+ $newMountPoint = self::verifyMountPoint($arguments['share']);
+ $absMountPoint = '/' . \OCP\User::getUser() . '/files' . $newMountPoint;
+ parent::__construct($storage, $absMountPoint, $arguments, $loader);
+ }
+
+ /**
+ * check if the parent folder exists otherwise move the mount point up
+ */
+ private static function verifyMountPoint(&$share) {
+
+ $mountPoint = basename($share['file_target']);
+ $parent = dirname($share['file_target']);
+
+ while (!\OC\Files\Filesystem::is_dir($parent)) {
+ $parent = dirname($parent);
+ }
+
+ $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(
+ \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint),
+ array(),
+ new \OC\Files\View('/' . \OCP\User::getUser() . '/files')
+ );
+
+ if($newMountPoint !== $share['file_target']) {
+ self::updateFileTarget($newMountPoint, $share);
+ $share['file_target'] = $newMountPoint;
+ $share['unique_name'] = true;
+ }
+
+ return $newMountPoint;
+ }
+
+ /**
+ * update fileTarget in the database if the mount point changed
+ * @param string $newPath
+ * @param array $share reference to the share which should be modified
+ * @return type
+ */
+ private static function updateFileTarget($newPath, &$share) {
+ // if the user renames a mount point from a group share we need to create a new db entry
+ // for the unique name
+ if ($share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP && empty($share['unique_name'])) {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,'
+ .' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
+ .' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
+ $arguments = array($share['item_type'], $share['item_source'], $share['item_target'],
+ 2, \OCP\User::getUser(), $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'],
+ $newPath, $share['token'], $share['id']);
+ } else {
+ // rename mount point
+ $query = \OC_DB::prepare(
+ 'Update `*PREFIX*share`
+ SET `file_target` = ?
+ WHERE `id` = ?'
+ );
+ $arguments = array($newPath, $share['id']);
+ }
+
+ $result = $query->execute($arguments);
+
+ return $result === 1 ? true : false;
+ }
+
+ /**
+ * Format a path to be relative to the /user/files/ directory
+ *
+ * @param string $path the absolute path
+ * @return string e.g. turns '/admin/files/test.txt' into '/test.txt'
+ */
+ private function stripUserFilesPath($path) {
+ $trimmed = ltrim($path, '/');
+ $split = explode('/', $trimmed);
+
+ // it is not a file relative to data/user/files
+ if (count($split) < 3 || $split[1] !== 'files') {
+ \OCP\Util::writeLog('file sharing',
+ 'Can not strip userid and "files/" from path: ' . $path,
+ \OCP\Util::DEBUG);
+ return false;
+ }
+
+ // skip 'user' and 'files'
+ $sliced = array_slice($split, 2);
+ $relPath = implode('/', $sliced);
+
+ return '/' . $relPath;
+ }
+
+ /**
+ * Move the mount point to $target
+ *
+ * @param string $target the target mount point
+ * @return bool
+ */
+ public function moveMount($target) {
+ // it shouldn't be possible to move a Shared storage into another one
+ list($targetStorage,) = Filesystem::resolvePath($target);
+ if ($targetStorage instanceof Shared) {
+ \OCP\Util::writeLog('file sharing',
+ 'It is not allowed to move one mount point into another one',
+ \OCP\Util::DEBUG);
+ return false;
+ }
+
+ $relTargetPath = $this->stripUserFilesPath($target);
+ $share = $this->storage->getShare();
+
+ $result = $this->updateFileTarget($relTargetPath, $share);
+
+ if ($result) {
+ $this->setMountPoint($target);
+ $this->storage->setUniqueName();
+ $this->storage->setMountPoint($relTargetPath);
+
+ } else {
+ \OCP\Util::writeLog('file sharing',
+ 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"',
+ \OCP\Util::ERROR);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Remove the mount points
+ *
+ * @return bool
+ */
+ public function removeMount() {
+ $storage = $this->getStorage();
+ $result = \OCP\Share::unshareFromSelf($storage->getItemType(), $storage->getMountPoint());
+
+ return $result;
+ }
+}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index f93982ee857..59de2dfa4c4 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -22,6 +22,8 @@
*/
namespace OC\Files\Storage;
+use OC\Files\Filesystem;
+use OCA\Files_Sharing\SharedMount;
/**
* Convert target path to source path and pass the function call to the correct storage provider
@@ -104,8 +106,8 @@ class Shared extends \OC\Files\Storage\Common {
*/
public function getPermissions($target = '') {
$permissions = $this->share['permissions'];
- // part file are always have delete permissions
- if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
+ // part files and the mount point always have delete permissions
+ if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
$permissions |= \OCP\PERMISSION_DELETE;
}
@@ -126,7 +128,18 @@ class Shared extends \OC\Files\Storage\Common {
return false;
}
+ /**
+ * Delete the directory if DELETE permission is granted
+ * @param string $path
+ * @return boolean
+ */
public function rmdir($path) {
+
+ // never delete a share mount point
+ if(empty($path)) {
+ return false;
+ }
+
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->rmdir($internalPath);
@@ -254,9 +267,17 @@ class Shared extends \OC\Files\Storage\Common {
return false;
}
+ /**
+ * Delete the file if DELETE permission is granted
+ * @param string $path
+ * @return boolean
+ */
public function unlink($path) {
- // Delete the file if DELETE permission is granted
- $path = ($path === false) ? '' : $path;
+
+ // never delete a share mount point
+ if (empty($path)) {
+ return false;
+ }
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
@@ -266,124 +287,14 @@ class Shared extends \OC\Files\Storage\Common {
return false;
}
- /**
- * Format a path to be relative to the /user/files/ directory
- * @param string $path the absolute path
- * @return string e.g. turns '/admin/files/test.txt' into '/test.txt'
- */
- private static function stripUserFilesPath($path) {
- $trimmed = ltrim($path, '/');
- $split = explode('/', $trimmed);
-
- // it is not a file relative to data/user/files
- if (count($split) < 3 || $split[1] !== 'files') {
- \OCP\Util::writeLog('file sharing',
- 'Can not strip userid and "files/" from path: ' . $path,
- \OCP\Util::DEBUG);
- return false;
- }
-
- // skip 'user' and 'files'
- $sliced = array_slice($split, 2);
- $relPath = implode('/', $sliced);
-
- return '/' . $relPath;
- }
-
- /**
- * rename a shared folder/file
- * @param string $sourcePath
- * @param string $targetPath
- * @return bool
- */
- private function renameMountPoint($sourcePath, $targetPath) {
-
- // it shouldn't be possible to move a Shared storage into another one
- list($targetStorage, ) = \OC\Files\Filesystem::resolvePath($targetPath);
- if ($targetStorage->instanceOfStorage('\OC\Files\Storage\Shared')) {
- \OCP\Util::writeLog('file sharing',
- 'It is not allowed to move one mount point into another one',
- \OCP\Util::DEBUG);
- return false;
- }
-
- $relTargetPath = $this->stripUserFilesPath($targetPath);
-
- if ($relTargetPath === false) {
- \OCP\Util::writeLog('file sharing', 'Wrong target path given: ' . $targetPath, \OCP\Util::ERROR);
- return false;
- }
-
- $result = self::updateFileTarget($relTargetPath, $this->share);
-
- if ($result) {
- // update the mount manager with the new paths
- $mountManager = \OC\Files\Filesystem::getMountManager();
- $mount = $mountManager->find($sourcePath);
- $mount->setMountPoint($targetPath . '/');
- $mountManager->addMount($mount);
- $mountManager->removeMount($sourcePath . '/');
- $this->setUniqueName();
- $this->setMountPoint($relTargetPath);
-
- } else {
- \OCP\Util::writeLog('file sharing',
- 'Could not rename mount point for shared folder "' . $sourcePath . '" to "' . $targetPath . '"',
- \OCP\Util::ERROR);
- }
-
- return (bool)$result;
- }
-
- /**
- * @update fileTarget in the database if the mount point changed
- * @param string $newPath
- * @param array $share reference to the share which should be modified
- * @return type
- */
- private static function updateFileTarget($newPath, &$share) {
- // if the user renames a mount point from a group share we need to create a new db entry
- // for the unique name
- if ($share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP &&
- (isset($share['unique_name']) && $share['unique_name'])) {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,'
- .' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
- .' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
- $arguments = array($share['item_type'], $share['item_source'], $share['item_target'],
- 2, \OCP\User::getUser(), $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'],
- $newPath, $share['token'], $share['id']);
-
- } else {
- // rename mount point
- $query = \OC_DB::prepare(
- 'Update `*PREFIX*share`
- SET `file_target` = ?
- WHERE `id` = ?'
- );
- $arguments = array($newPath, $share['id']);
- }
-
- return $query->execute($arguments);
- }
-
public function rename($path1, $path2) {
- $sourceMountPoint = \OC\Files\Filesystem::getMountPoint($path1);
- $targetMountPoint = \OC\Files\Filesystem::getMountPoint($path2);
- $relPath1 = \OCA\Files_Sharing\Helper::stripUserFilesPath($path1);
- $relPath2 = \OCA\Files_Sharing\Helper::stripUserFilesPath($path2);
-
- // if we renamed the mount point we need to adjust the file_target in the
- // database
- if (\OC\Files\Filesystem::normalizePath($sourceMountPoint) === \OC\Files\Filesystem::normalizePath($path1)) {
- return $this->renameMountPoint($path1, $path2);
- }
+ // we need the paths relative to data/user/files
+ $relPath1 = $this->getMountPoint() . '/' . $path1;
+ $relPath2 = $this->getMountPoint() . '/' . $path2;
-
- if ( // Within the same mount point, we only need UPDATE permissions
- ($sourceMountPoint === $targetMountPoint && $this->isUpdatable($sourceMountPoint)) ||
- // otherwise DELETE and CREATE permissions required
- ($this->isDeletable($path1) && $this->isCreatable(dirname($path2)))) {
+ // check for update permissions on the share
+ if ($this->isUpdatable('')) {
$pathinfo = pathinfo($relPath1);
// for part files we need to ask for the owner and path from the parent directory because
@@ -486,48 +397,29 @@ class Shared extends \OC\Files\Storage\Common {
public static function setup($options) {
$shares = \OCP\Share::getItemsSharedWith('file');
+ $manager = Filesystem::getMountManager();
+ $loader = Filesystem::getLoader();
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
|| $shares
) {
foreach ($shares as $share) {
- self::verifyMountPoint($share);
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
- array(
- 'share' => $share,
- ),
- $options['user_dir'] . '/' . $share['file_target']);
+ // don't mount shares where we have no permissions
+ if ($share['permissions'] > 0) {
+ $mount = new SharedMount(
+ '\OC\Files\Storage\Shared',
+ $options['user_dir'] . '/' . $share['file_target'],
+ array(
+ 'share' => $share,
+ ),
+ $loader
+ );
+ $manager->addMount($mount);
+ }
}
}
}
/**
- * check if the parent folder exists otherwise move the mount point up
- *
- * @param array $share reference to the share we want to check
- */
- private static function verifyMountPoint(&$share) {
- $mountPoint = basename($share['file_target']);
- $parent = dirname($share['file_target']);
-
- while (!\OC\Files\Filesystem::is_dir($parent)) {
- $parent = dirname($parent);
- }
-
- $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(
- \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint),
- array(),
- new \OC\Files\View('/' . \OCP\User::getUser() . '/files')
- );
-
- if($newMountPoint !== $share['file_target']) {
-
- self::updateFileTarget($newMountPoint, $share);
- $share['file_target'] = $newMountPoint;
-
- }
- }
-
- /**
* return mount point of share, relative to data/user/files
*
* @return string
@@ -536,22 +428,41 @@ class Shared extends \OC\Files\Storage\Common {
return $this->share['file_target'];
}
- private function setMountPoint($path) {
+ public function setMountPoint($path) {
$this->share['file_target'] = $path;
}
+ public function getShareType() {
+ return $this->share['share_type'];
+ }
+
+ /**
+ * does the group share already has a user specific unique name
+ * @return bool
+ */
+ public function uniqueNameSet() {
+ return (isset($this->share['unique_name']) && $this->share['unique_name']);
+ }
+
/**
* the share now uses a unique name of this user
*
* @brief the share now uses a unique name of this user
*/
- private function setUniqueName() {
+ public function setUniqueName() {
$this->share['unique_name'] = true;
}
/**
- * @brief get the user who shared the file
- *
+ * get share ID
+ * @return integer unique share ID
+ */
+ public function getShareId() {
+ return $this->share['id'];
+ }
+
+ /**
+ * get the user who shared the file
* @return string
*/
public function getSharedFrom() {
@@ -559,6 +470,13 @@ class Shared extends \OC\Files\Storage\Common {
}
/**
+ * @return array
+ */
+ public function getShare() {
+ return $this->share;
+ }
+
+ /**
* return share type, can be "file" or "folder"
* @return string
*/