aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:37:27 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:37:27 +0200
commitcd01c440a01744d666df275cb7941fa29d2283dd (patch)
treed09caccace60dcfcc42e9b00ae2d810ec29643cc
parentcdcabbd0b3f6209b2a312b30a84c381f125bcf68 (diff)
parentb53d6598f10c97318fbf065369f5b097eb134e28 (diff)
downloadnextcloud-server-cd01c440a01744d666df275cb7941fa29d2283dd.tar.gz
nextcloud-server-cd01c440a01744d666df275cb7941fa29d2283dd.zip
Merge pull request #23919 from owncloud/cyclyc-share-dep-example
SharedStorage to new sharing code + cleanup
-rw-r--r--apps/dav/lib/connector/sabre/node.php2
-rw-r--r--apps/files_sharing/appinfo/application.php3
-rw-r--r--apps/files_sharing/lib/mountprovider.php25
-rw-r--r--apps/files_sharing/lib/scanner.php6
-rw-r--r--apps/files_sharing/lib/sharedmount.php97
-rw-r--r--apps/files_sharing/lib/sharedpropagator.php3
-rw-r--r--apps/files_sharing/lib/sharedstorage.php452
-rw-r--r--apps/files_sharing/lib/updater.php17
-rw-r--r--apps/files_sharing/tests/api.php46
-rw-r--r--apps/files_sharing/tests/cache.php101
-rw-r--r--apps/files_sharing/tests/etagpropagation.php148
-rw-r--r--apps/files_sharing/tests/groupetagpropagation.php30
-rw-r--r--apps/files_sharing/tests/locking.php8
-rw-r--r--apps/files_sharing/tests/permissions.php63
-rw-r--r--apps/files_sharing/tests/share.php383
-rw-r--r--apps/files_sharing/tests/sharedmount.php194
-rw-r--r--apps/files_sharing/tests/sharedstorage.php226
-rw-r--r--apps/files_sharing/tests/sizepropagation.php20
-rw-r--r--apps/files_sharing/tests/testcase.php31
-rw-r--r--apps/files_sharing/tests/unsharechildren.php17
-rw-r--r--apps/files_sharing/tests/updater.php36
-rw-r--r--apps/files_sharing/tests/watcher.php34
-rw-r--r--apps/files_trashbin/tests/storage.php22
-rw-r--r--apps/files_trashbin/tests/trashbin.php11
-rw-r--r--apps/files_versions/tests/versions.php81
-rw-r--r--lib/private/Share20/Manager.php51
-rw-r--r--lib/private/files/cache/wrapper/cachejail.php16
-rw-r--r--lib/private/files/config/cachedmountinfo.php14
-rw-r--r--lib/private/files/config/lazystoragemountinfo.php74
-rw-r--r--lib/private/files/config/usermountcache.php11
-rw-r--r--lib/private/files/mount/mountpoint.php9
-rw-r--r--lib/private/files/storage/common.php24
-rw-r--r--lib/private/files/storage/wrapper/jail.php46
-rw-r--r--lib/private/files/storage/wrapper/wrapper.php6
-rw-r--r--lib/private/helper.php2
-rw-r--r--lib/public/files/mount/imountpoint.php8
-rw-r--r--tests/lib/share20/managertest.php10
37 files changed, 1083 insertions, 1244 deletions
diff --git a/apps/dav/lib/connector/sabre/node.php b/apps/dav/lib/connector/sabre/node.php
index eaba6713992..979149fc937 100644
--- a/apps/dav/lib/connector/sabre/node.php
+++ b/apps/dav/lib/connector/sabre/node.php
@@ -224,7 +224,7 @@ abstract class Node implements \Sabre\DAV\INode {
if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
/** @var \OC\Files\Storage\Shared $storage */
- $permissions = (int)$storage->getShare()['permissions'];
+ $permissions = (int)$storage->getShare()->getPermissions();
} else {
$permissions = $storage->getPermissions($path);
}
diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php
index 64c7517456d..5233b343830 100644
--- a/apps/files_sharing/appinfo/application.php
+++ b/apps/files_sharing/appinfo/application.php
@@ -111,7 +111,8 @@ class Application extends App {
/** @var \OCP\IServerContainer $server */
$server = $c->query('ServerContainer');
return new MountProvider(
- $server->getConfig()
+ $server->getConfig(),
+ $server->getShareManager()
);
});
diff --git a/apps/files_sharing/lib/mountprovider.php b/apps/files_sharing/lib/mountprovider.php
index 6c8bbb62ee7..8e133951293 100644
--- a/apps/files_sharing/lib/mountprovider.php
+++ b/apps/files_sharing/lib/mountprovider.php
@@ -22,12 +22,11 @@
namespace OCA\Files_Sharing;
-use OC\Files\Filesystem;
-use OC\User\NoUserException;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IUser;
+use OCP\Share\IManager;
class MountProvider implements IMountProvider {
/**
@@ -36,10 +35,17 @@ class MountProvider implements IMountProvider {
protected $config;
/**
+ * @var IManager
+ */
+ protected $shareManager;
+
+ /**
* @param \OCP\IConfig $config
+ * @param IManager $shareManager
*/
- public function __construct(IConfig $config) {
+ public function __construct(IConfig $config, IManager $shareManager) {
$this->config = $config;
+ $this->shareManager = $shareManager;
}
@@ -51,18 +57,21 @@ class MountProvider implements IMountProvider {
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
- $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
- $shares = array_filter($shares, function ($share) {
- return $share['permissions'] > 0;
+ $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
+ $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
+ $shares = array_filter($shares, function (\OCP\Share\IShare $share) {
+ return $share->getPermissions() > 0;
});
+
$mounts = [];
foreach ($shares as $share) {
+
$mounts[] = new SharedMount(
'\OC\Files\Storage\Shared',
$mounts,
[
- 'share' => $share,
- 'user' => $user->getUID()
+ 'user' => $user->getUID(),
+ 'newShare' => $share,
],
$storageFactory
);
diff --git a/apps/files_sharing/lib/scanner.php b/apps/files_sharing/lib/scanner.php
index 8b32d014a08..2e951423aa2 100644
--- a/apps/files_sharing/lib/scanner.php
+++ b/apps/files_sharing/lib/scanner.php
@@ -42,8 +42,10 @@ class SharedScanner extends Scanner {
*/
public function getData($path) {
$data = parent::getData($path);
- $sourcePath = $this->storage->getSourcePath($path);
- list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath);
+ if ($data === null) {
+ return null;
+ }
+ list($sourceStorage, $internalPath) = $this->storage->resolvePath($path);
$data['permissions'] = $sourceStorage->getPermissions($internalPath);
return $data;
}
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
index 311e81269db..4aed80b12b2 100644
--- a/apps/files_sharing/lib/sharedmount.php
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -49,6 +49,9 @@ class SharedMount extends MountPoint implements MoveableMount {
*/
private $user;
+ /** @var \OCP\Share\IShare */
+ private $share;
+
/**
* @param string $storage
* @param SharedMount[] $mountpoints
@@ -58,23 +61,24 @@ class SharedMount extends MountPoint implements MoveableMount {
public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) {
$this->user = $arguments['user'];
$this->recipientView = new View('/' . $this->user . '/files');
- $newMountPoint = $this->verifyMountPoint($arguments['share'], $mountpoints);
+ $this->share = $arguments['newShare'];
+ $newMountPoint = $this->verifyMountPoint($this->share, $mountpoints);
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
- $arguments['ownerView'] = new View('/' . $arguments['share']['uid_owner'] . '/files');
+ $arguments['ownerView'] = new View('/' . $this->share->getShareOwner() . '/files');
parent::__construct($storage, $absMountPoint, $arguments, $loader);
}
/**
* check if the parent folder exists otherwise move the mount point up
*
- * @param array $share
+ * @param \OCP\Share\IShare $share
* @param SharedMount[] $mountpoints
* @return string
*/
- private function verifyMountPoint(&$share, array $mountpoints) {
+ private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) {
- $mountPoint = basename($share['file_target']);
- $parent = dirname($share['file_target']);
+ $mountPoint = basename($share->getTarget());
+ $parent = dirname($share->getTarget());
if (!$this->recipientView->is_dir($parent)) {
$parent = Helper::getShareFolder();
@@ -86,16 +90,27 @@ class SharedMount extends MountPoint implements MoveableMount {
$mountpoints
);
- if ($newMountPoint !== $share['file_target']) {
+ if ($newMountPoint !== $share->getTarget()) {
$this->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 \OCP\Share\IShare $share
+ * @return bool
+ */
+ private function updateFileTarget($newPath, &$share) {
+ $share->setTarget($newPath);
+ \OC::$server->getShareManager()->moveShare($share, $this->user);
+ }
+
+
+ /**
* @param string $path
* @param View $view
* @param SharedMount[] $mountpoints
@@ -110,7 +125,7 @@ class SharedMount extends MountPoint implements MoveableMount {
// Helper function to find existing mount points
$mountpointExists = function($path) use ($mountpoints) {
foreach ($mountpoints as $mountpoint) {
- if ($mountpoint->getShare()['file_target'] === $path) {
+ if ($mountpoint->getShare()->getTarget() === $path) {
return true;
}
}
@@ -127,38 +142,6 @@ class SharedMount extends MountPoint implements MoveableMount {
}
/**
- * 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 bool
- */
- private 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 = \OCP\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, $this->user, $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'],
- $newPath, $share['token'], $share['id']);
- } else {
- // rename mount point
- $query = \OCP\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
@@ -197,20 +180,11 @@ class SharedMount extends MountPoint implements MoveableMount {
$result = true;
- if (!empty($share['grouped'])) {
- foreach ($share['grouped'] as $s) {
- $result = $this->updateFileTarget($relTargetPath, $s) && $result;
- }
- } else {
- $result = $this->updateFileTarget($relTargetPath, $share) && $result;
- }
-
- if ($result) {
+ try {
+ $this->updateFileTarget($relTargetPath, $share);
$this->setMountPoint($target);
- $this->storage->setUniqueName();
$this->storage->setMountPoint($relTargetPath);
-
- } else {
+ } catch (\Exception $e) {
\OCP\Util::writeLog('file sharing',
'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"',
\OCP\Util::ERROR);
@@ -235,11 +209,18 @@ class SharedMount extends MountPoint implements MoveableMount {
}
/**
- * @return array
+ * @return \OCP\Share\IShare
*/
public function getShare() {
- /** @var $storage \OC\Files\Storage\Shared */
- $storage = $this->getStorage();
- return $storage->getShare();
+ return $this->share;
+ }
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ */
+ public function getStorageRootId() {
+ return $this->share->getNodeId();
}
}
diff --git a/apps/files_sharing/lib/sharedpropagator.php b/apps/files_sharing/lib/sharedpropagator.php
index 29735934499..8de90b9552b 100644
--- a/apps/files_sharing/lib/sharedpropagator.php
+++ b/apps/files_sharing/lib/sharedpropagator.php
@@ -36,9 +36,8 @@ class SharedPropagator extends Propagator {
* @return \array[] all propagated entries
*/
public function propagateChange($internalPath, $time, $sizeDifference = 0) {
- $source = $this->storage->getSourcePath($internalPath);
/** @var \OC\Files\Storage\Storage $storage */
- list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
+ list($storage, $sourceInternalPath) = $this->storage->resolvePath($internalPath);
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference);
}
}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 8f4888d20e2..48ab3fad5f6 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -41,21 +41,18 @@ use OCP\Lock\ILockingProvider;
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
-class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
+class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
private $share; // the shared resource
- private $files = array();
+
+ /** @var \OCP\Share\IShare */
+ private $newShare;
/**
* @var \OC\Files\View
*/
private $ownerView;
- /**
- * @var string
- */
- private $user;
-
private $initialized = false;
/**
@@ -68,16 +65,28 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
*/
private $sourceStorage;
+ /** @var string */
+ private $user;
+
/**
* @var \OCP\ILogger
*/
private $logger;
public function __construct($arguments) {
- $this->share = $arguments['share'];
$this->ownerView = $arguments['ownerView'];
- $this->user = $arguments['user'];
$this->logger = \OC::$server->getLogger();
+ $this->newShare = $arguments['newShare'];
+ $this->user = $arguments['user'];
+
+ Filesystem::initMountPoints($this->newShare->getShareOwner());
+ $sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
+ list($storage, $internalPath) = $this->ownerView->resolvePath($sourcePath);
+
+ parent::__construct([
+ 'storage' => $storage,
+ 'root' => $internalPath,
+ ]);
}
private function init() {
@@ -86,8 +95,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
}
$this->initialized = true;
try {
- Filesystem::initMountPoints($this->share['uid_owner']);
- $sourcePath = $this->ownerView->getPath($this->share['file_source']);
+ Filesystem::initMountPoints($this->newShare->getShareOwner());
+ $sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
} catch (\Exception $e) {
@@ -115,59 +124,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return int
*/
public function getSourceId() {
- return (int)$this->share['file_source'];
- }
-
- /**
- * Get the source file path, permissions, and owner for a shared file
- *
- * @param string $target Shared target file path
- * @return array Returns array with the keys path, permissions, and owner or false if not found
- */
- public function getFile($target) {
- $this->init();
- 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), $this->getShare());
- if ($source) {
- $source['path'] .= '.part';
- // All partial files have delete permission
- $source['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
- }
- } else {
- $source = \OC_Share_Backend_File::getSource($target, $this->getShare());
- }
- $this->files[$target] = $source;
- }
- return $this->files[$target];
- }
-
- /**
- * Get the source file path for a shared file
- *
- * @param string $target Shared target file path
- * @return string|false source file path or false if not found
- */
- public function getSourcePath($target) {
- if (!$this->isValid()){
- return false;
- }
- $source = $this->getFile($target);
- if ($source) {
- if (!isset($source['fullPath'])) {
- \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
- $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
- if (is_array($mount) && !empty($mount)) {
- $this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint() . $source['path'];
- } else {
- $this->files[$target]['fullPath'] = false;
- \OCP\Util::writeLog('files_sharing', "Unable to get mount for shared storage '" . $source['storage'] . "' user '" . $source['fileOwner'] . "'", \OCP\Util::ERROR);
- }
- }
- return $this->files[$target]['fullPath'];
- }
- return false;
+ return $this->newShare->getNodeId();
}
/**
@@ -180,7 +137,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
if (!$this->isValid()) {
return 0;
}
- $permissions = $this->share['permissions'];
+ $permissions = $this->newShare->getPermissions();
// part files and the mount point always have delete permissions
if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
$permissions |= \OCP\Constants::PERMISSION_DELETE;
@@ -193,84 +150,6 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
return $permissions;
}
- public function mkdir($path) {
- if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
- return false;
- } else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->mkdir($internalPath);
- }
- 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);
- }
- return false;
- }
-
- public function opendir($path) {
- $source = $this->getSourcePath($path);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->opendir($internalPath);
- }
-
- public function is_dir($path) {
- $source = $this->getSourcePath($path);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->is_dir($internalPath);
- }
-
- public function is_file($path) {
- if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->is_file($internalPath);
- }
- return false;
- }
-
- public function stat($path) {
- if ($path == '' || $path == '/') {
- $stat['size'] = $this->filesize($path);
- $stat['mtime'] = $this->filemtime($path);
- return $stat;
- } else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->stat($internalPath);
- }
- return false;
- }
-
- public function filetype($path) {
- if ($path == '' || $path == '/') {
- return 'dir';
- } else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->filetype($internalPath);
- }
- return false;
- }
-
- public function filesize($path) {
- $source = $this->getSourcePath($path);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->filesize($internalPath);
- }
-
public function isCreatable($path) {
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
}
@@ -301,127 +180,6 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
}
- public function file_exists($path) {
- if ($path == '' || $path == '/') {
- return true;
- } else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->file_exists($internalPath);
- }
- return false;
- }
-
- public function filemtime($path) {
- $source = $this->getSourcePath($path);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->filemtime($internalPath);
- }
-
- public function file_get_contents($path) {
- $source = $this->getSourcePath($path);
- if ($source) {
- $info = array(
- 'target' => $this->getMountPoint() . $path,
- 'source' => $source,
- );
- \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->file_get_contents($internalPath);
- }
- }
-
- public function file_put_contents($path, $data) {
- 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->getMountPoint() . '/' . $path,
- 'source' => $source,
- );
- \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- $result = $storage->file_put_contents($internalPath, $data);
- return $result;
- }
- return false;
- }
-
- /**
- * Delete the file if DELETE permission is granted
- *
- * @param string $path
- * @return boolean
- */
- public function unlink($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);
- return $storage->unlink($internalPath);
- }
- }
- return false;
- }
-
- public function rename($path1, $path2) {
- $this->init();
- // we need the paths relative to data/user/files
- $relPath1 = $this->getMountPoint() . '/' . $path1;
- $relPath2 = $this->getMountPoint() . '/' . $path2;
- $pathinfo = pathinfo($relPath1);
-
- $isPartFile = (isset($pathinfo['extension']) && $pathinfo['extension'] === 'part');
- $targetExists = $this->file_exists($path2);
- $sameFolder = (dirname($relPath1) === dirname($relPath2));
- if ($targetExists || ($sameFolder && !$isPartFile)) {
- // note that renaming a share mount point is always allowed
- if (!$this->isUpdatable('')) {
- return false;
- }
- } else {
- if (!$this->isCreatable('')) {
- return false;
- }
- }
-
-
- /**
- * @var \OC\Files\Storage\Storage $sourceStorage
- */
- list($sourceStorage, $sourceInternalPath) = $this->resolvePath($path1);
- /**
- * @var \OC\Files\Storage\Storage $targetStorage
- */
- list($targetStorage, $targetInternalPath) = $this->resolvePath($path2);
-
- return $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
- }
-
- public function copy($path1, $path2) {
- // Copy the file if CREATE permission is granted
- if ($this->isCreatable(dirname($path2))) {
- /**
- * @var \OC\Files\Storage\Storage $sourceStorage
- */
- list($sourceStorage, $sourceInternalPath) = $this->resolvePath($path1);
- /**
- * @var \OC\Files\Storage\Storage $targetStorage
- */
- list($targetStorage, $targetInternalPath) = $this->resolvePath($path2);
-
- return $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
- }
- return false;
- }
-
public function fopen($path, $mode) {
if ($source = $this->getSourcePath($path)) {
switch ($mode) {
@@ -465,43 +223,34 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
'mode' => $mode,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->fopen($internalPath, $mode);
+ return parent::fopen($path, $mode);
}
return false;
}
- public function getMimeType($path) {
- if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->getMimeType($internalPath);
- }
- return false;
- }
-
- public function free_space($path) {
- $source = $this->getSourcePath($path);
- if ($source) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->free_space($internalPath);
- }
- return \OCP\Files\FileInfo::SPACE_UNKNOWN;
- }
+ /**
+ * see http://php.net/manual/en/function.rename.php
+ *
+ * @param string $path1
+ * @param string $path2
+ * @return bool
+ */
+ public function rename($path1, $path2) {
+ $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
+ $targetExists = $this->file_exists($path2);
+ $sameFodler = dirname($path1) === dirname($path2);
- public function getLocalFile($path) {
- if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->getLocalFile($internalPath);
+ if ($targetExists || ($sameFodler && !$isPartFile)) {
+ if (!$this->isUpdatable('')) {
+ return false;
+ }
+ } else {
+ if (!$this->isCreatable('')) {
+ return false;
+ }
}
- return false;
- }
- public function touch($path, $mtime = null) {
- if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->touch($internalPath, $mtime);
- }
- return false;
+ return parent::rename($path1, $path2);
}
/**
@@ -510,33 +259,21 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return string
*/
public function getMountPoint() {
- return $this->share['file_target'];
- }
-
- public function setMountPoint($path) {
- $this->share['file_target'] = $path;
- }
-
- public function getShareType() {
- return $this->share['share_type'];
+ return $this->newShare->getTarget();
}
/**
- * does the group share already has a user specific unique name
- *
- * @return bool
+ * @param string $path
*/
- public function uniqueNameSet() {
- return (isset($this->share['unique_name']) && $this->share['unique_name']);
+ public function setMountPoint($path) {
+ $this->newShare->setTarget($path);
}
/**
- * the share now uses a unique name of this user
- *
- * @brief the share now uses a unique name of this user
+ * @return int
*/
- public function setUniqueName() {
- $this->share['unique_name'] = true;
+ public function getShareType() {
+ return $this->newShare->getShareType();
}
/**
@@ -545,7 +282,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return integer unique share ID
*/
public function getShareId() {
- return $this->share['id'];
+ return $this->newShare->getId();
}
/**
@@ -554,14 +291,14 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return string
*/
public function getSharedFrom() {
- return $this->share['uid_owner'];
+ return $this->newShare->getShareOwner();
}
/**
- * @return array
+ * @return \OCP\Share\IShare
*/
public function getShare() {
- return $this->share;
+ return $this->newShare;
}
/**
@@ -570,11 +307,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return string
*/
public function getItemType() {
- return $this->share['item_type'];
- }
-
- public function hasUpdated($path, $time) {
- return $this->filemtime($path) > $time;
+ return $this->newShare->getNodeType();
}
public function getCache($path = '', $storage = null) {
@@ -603,22 +336,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
}
public function getOwner($path) {
- if ($path == '') {
- $path = $this->getMountPoint();
- }
- $source = $this->getFile($path);
- if ($source) {
- return $source['fileOwner'];
- }
- return false;
- }
-
- public function getETag($path) {
- if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
- return $storage->getETag($internalPath);
- }
- return null;
+ return $this->newShare->getShareOwner();
}
/**
@@ -627,50 +345,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
* @return bool
*/
public function unshareStorage() {
- $result = true;
- if (!empty($this->share['grouped'])) {
- foreach ($this->share['grouped'] as $share) {
- $result = $result && \OCP\Share::unshareFromSelf($share['item_type'], $share['file_target']);
- }
- }
- $result = $result && \OCP\Share::unshareFromSelf($this->getItemType(), $this->getMountPoint());
-
- return $result;
- }
-
- /**
- * Resolve the path for the source of the share
- *
- * @param string $path
- * @return array
- */
- public function resolvePath($path) {
- $source = $this->getSourcePath($path);
- return \OC\Files\Filesystem::resolvePath($source);
- }
-
- /**
- * @param \OCP\Files\Storage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @return bool
- */
- public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
- /** @var \OCP\Files\Storage $targetStorage */
- list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath);
- return $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
- }
-
- /**
- * @param \OCP\Files\Storage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @return bool
- */
- public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
- /** @var \OCP\Files\Storage $targetStorage */
- list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath);
- return $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+ \OC::$server->getShareManager()->deleteFromSelf($this->newShare, $this->user);
+ return true;
}
/**
@@ -685,7 +361,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
// lock the parent folders of the owner when locking the share as recipient
if ($path === '') {
- $sourcePath = $this->ownerView->getPath($this->share['file_source']);
+ $sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
}
}
@@ -701,7 +377,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
$targetStorage->releaseLock($targetInternalPath, $type, $provider);
// unlock the parent folders of the owner when unlocking the share as recipient
if ($path === '') {
- $sourcePath = $this->ownerView->getPath($this->share['file_source']);
+ $sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
}
}
@@ -735,14 +411,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
// shares do not participate in availability logic
}
- public function isLocal() {
- $this->init();
- $ownerPath = $this->ownerView->getPath($this->share['item_source']);
- list($targetStorage) = $this->ownerView->resolvePath($ownerPath);
- return $targetStorage->isLocal();
- }
-
public function getSourceStorage() {
return $this->sourceStorage;
}
+
}
diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php
index 10da2462807..0e6433b1122 100644
--- a/apps/files_sharing/lib/updater.php
+++ b/apps/files_sharing/lib/updater.php
@@ -81,8 +81,10 @@ class Shared_Updater {
$src = $userFolder->get($path);
- $type = $src instanceof \OCP\Files\File ? 'file' : 'folder';
- $shares = \OCP\Share::getItemShared($type, $src->getId());
+ $shareManager = \OC::$server->getShareManager();
+
+ $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1);
+ $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1));
// If the path we move is not a share we don't care
if (empty($shares)) {
@@ -96,14 +98,13 @@ class Shared_Updater {
return;
}
- $parenShare = $dstMount->getShare();
+ $newOwner = $dstMount->getShare()->getShareOwner();
+ //Ownership is moved over
foreach ($shares as $share) {
- $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- $qb->update('share')
- ->set('parent', $qb->createNamedParameter($parenShare['id']))
- ->where($qb->expr()->eq('id', $qb->createNamedParameter($share['id'])))
- ->execute();
+ /** @var \OCP\Share\IShare $share */
+ $share->setShareOwner($newOwner);
+ $shareManager->updateShare($share);
}
}
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 08f8b6f243d..0a61e9a9fa2 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -40,9 +40,6 @@ class Test_Files_Sharing_Api extends TestCase {
private static $tempStorage;
- /** @var \OCP\Share\IManager */
- private $shareManager;
-
/** @var \OCP\Files\Folder */
private $userFolder;
@@ -66,7 +63,6 @@ class Test_Files_Sharing_Api extends TestCase {
$this->view->file_put_contents($this->folder.$this->filename, $this->data);
$this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
- $this->shareManager = \OC::$server->getShareManager();
$this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
}
@@ -1195,10 +1191,13 @@ class Test_Files_Sharing_Api extends TestCase {
$fileInfo = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
-
- $this->assertTrue($result);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
// user2 shares a file from the folder as link
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
@@ -1215,14 +1214,20 @@ class Test_Files_Sharing_Api extends TestCase {
$this->assertTrue($fileInfo2 instanceof \OC\Files\FileInfo);
+ $pass = true;
try {
- $result2 = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3, 31);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ 'localDir',
+ self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER3,
+ \OCP\Constants::PERMISSION_ALL
+ );
} catch (\Exception $e) {
- $result2 = false;
+ $pass = false;
}
- $this->assertFalse($result2);
+ $this->assertFalse($pass);
//cleanup
@@ -1232,8 +1237,7 @@ class Test_Files_Sharing_Api extends TestCase {
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($share);
}
/**
@@ -1264,10 +1268,13 @@ class Test_Files_Sharing_Api extends TestCase {
$fileInfo = $this->view->getFileInfo($this->folder);
// user 1 shares the mount point folder with user2
- $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
-
- $this->assertTrue($result);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
// user2: check that mount point name appears correctly
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
@@ -1279,8 +1286,7 @@ class Test_Files_Sharing_Api extends TestCase {
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($share);
\OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook');
}
diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php
index fcc5a343a03..dd727c1c6f2 100644
--- a/apps/files_sharing/tests/cache.php
+++ b/apps/files_sharing/tests/cache.php
@@ -26,27 +26,6 @@
*/
use OCA\Files_sharing\Tests\TestCase;
-/**
- * ownCloud
- *
- * @author Vincent Petry, Bjoern Schiessle
- * @copyright 2014 Vincent Petry <pvince81@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
- * 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 Test_Files_Sharing_Cache
@@ -72,9 +51,14 @@ class Test_Files_Sharing_Cache extends TestCase {
/** @var \OC\Files\Storage\Storage */
protected $sharedStorage;
+ /** @var \OCP\Share\IManager */
+ protected $shareManager;
+
protected function setUp() {
parent::setUp();
+ $this->shareManager = \OC::$server->getShareManager();
+
\OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One');
\OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two');
@@ -101,13 +85,25 @@ class Test_Files_Sharing_Cache extends TestCase {
$this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
-
- $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
- \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+
+ $node = $rootFolder->get('container/shareddir');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $this->shareManager->createShare($share);
+
+ $node = $rootFolder->get('container/shared single file.txt');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
+ $this->shareManager->createShare($share);
// login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -125,13 +121,10 @@ class Test_Files_Sharing_Cache extends TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
-
- $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
- \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
+ $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER);
+ foreach ($shares as $share) {
+ $this->shareManager->deleteShare($share);
+ }
$this->view->deleteAll('container');
@@ -392,9 +385,15 @@ class Test_Files_Sharing_Cache extends TestCase {
function testGetFolderContentsWhenSubSubdirShared() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $fileinfo = $this->view->getFileInfo('container/shareddir/subdir');
- \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER3, 31);
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $node = $rootFolder->get('container/shareddir/subdir');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = $this->shareManager->createShare($share);
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
@@ -430,8 +429,7 @@ class Test_Files_Sharing_Cache extends TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER3);
+ $this->shareManager->deleteShare($share);
}
/**
@@ -470,7 +468,17 @@ class Test_Files_Sharing_Cache extends TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::file_put_contents('test.txt', 'foo');
$info = \OC\Files\Filesystem::getFileInfo('test.txt');
- \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
+
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $node = $rootFolder->get('test.txt');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
+ $this->shareManager->createShare($share);
+
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -491,7 +499,16 @@ class Test_Files_Sharing_Cache extends TestCase {
\OC\Files\Filesystem::touch('foo/bar/test.txt');
$folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
$fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
+
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $node = $rootFolder->get('foo');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $this->shareManager->createShare($share);
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
diff --git a/apps/files_sharing/tests/etagpropagation.php b/apps/files_sharing/tests/etagpropagation.php
index 55972dd9221..2f3604e63cd 100644
--- a/apps/files_sharing/tests/etagpropagation.php
+++ b/apps/files_sharing/tests/etagpropagation.php
@@ -50,13 +50,15 @@ class EtagPropagation extends PropagationTestCase {
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
+ $rootFolder = \OC::$server->getRootFolder();
+ $shareManager = \OC::$server->getShareManager();
+
$this->rootView = new View('');
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/sub1/sub2/folder/inside');
$view1->mkdir('/directReshare');
$view1->mkdir('/sub1/sub2/folder/other');
- $view1->mkdir('/sub1/sub2/folder/other');
$view1->file_put_contents('/foo.txt', 'foobar');
$view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
$view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
@@ -64,30 +66,90 @@ class EtagPropagation extends PropagationTestCase {
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
$fileInfo = $view1->getFileInfo('/foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
- \OCP\Share::shareItem('file', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
+
+ $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
+ ->get('/foo.txt');
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
+ $shareManager->createShare($share);
+ $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
+ ->get('/sub1/sub2/folder');
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $shareManager->createShare($share);
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $shareManager->createShare($share);
+
$folderInfo = $view1->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
+
+ $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
+ ->get('/directReshare');
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $shareManager->createShare($share);
+
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
+ /*
+ * User 2
+ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$view2->mkdir('/sub1/sub2');
$view2->rename('/folder', '/sub1/sub2/folder');
$insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
$this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo);
- \OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
+
+ $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
+ ->get('/sub1/sub2/folder/inside');
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $shareManager->createShare($share);
+
$folderInfo = $view2->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
+
+ $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
+ ->get('/directReshare');
+ $share = $shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $shareManager->createShare($share);
+
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
+ /*
+ * User 3
+ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
$view3->mkdir('/sub1/sub2');
@@ -96,6 +158,9 @@ class EtagPropagation extends PropagationTestCase {
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
+ /*
+ * User 4
+ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
$view4->mkdir('/sub1/sub2');
@@ -108,6 +173,7 @@ class EtagPropagation extends PropagationTestCase {
$this->loginAsUser($user);
foreach ($ids as $id) {
$path = $this->rootView->getPath($id);
+ $ls = $this->rootView->getDirectoryContent($path);
$this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
}
}
@@ -202,19 +268,40 @@ class EtagPropagation extends PropagationTestCase {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
- $folderId = $folderInfo->getId();
- $this->assertTrue(
- \OCP\Share::unshare(
- 'folder',
- $folderId,
- \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2
- )
- );
+
+ $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
+ $shareManager = \OC::$server->getShareManager();
+ $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true);
+
+ foreach ($shares as $share) {
+ if ($share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2) {
+ $shareManager->deleteShare($share);
+ }
+ }
+
$this->assertEtagsForFoldersChanged([
// direct recipient affected
self::TEST_FILES_SHARING_API_USER2,
- // reshare recipient affected
+ ]);
+
+ $this->assertAllUnchanged();
+ }
+
+ public function testOwnerUnsharesFlatReshares() {
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
+ $folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside');
+ $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
+
+ $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
+ $shareManager = \OC::$server->getShareManager();
+ $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true);
+
+ foreach ($shares as $share) {
+ $shareManager->deleteShare($share);
+ }
+
+ $this->assertEtagsForFoldersChanged([
+ // direct recipient affected
self::TEST_FILES_SHARING_API_USER4,
]);
@@ -223,14 +310,13 @@ class EtagPropagation extends PropagationTestCase {
public function testRecipientUnsharesFromSelf() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
+ $ls = $this->rootView->getDirectoryContent('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/');
$this->assertTrue(
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder')
);
$this->assertEtagsForFoldersChanged([
// direct recipient affected
self::TEST_FILES_SHARING_API_USER2,
- // reshare recipient affected
- self::TEST_FILES_SHARING_API_USER4,
]);
$this->assertAllUnchanged();
@@ -240,8 +326,11 @@ class EtagPropagation extends PropagationTestCase {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
- $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
- self::TEST_FILES_SHARING_API_USER3]);
+ $this->assertEtagsForFoldersChanged([
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER3
+ ]);
$this->assertAllUnchanged();
}
@@ -350,14 +439,21 @@ class EtagPropagation extends PropagationTestCase {
}
public function testEtagChangeOnPermissionsChange() {
- $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
+ $userFolder = $this->rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $node = $userFolder->get('/sub1/sub2/folder');
- $view = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
- $folderInfo = $view->getFileInfo('/sub1/sub2/folder');
+ $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node);
+ /** @var \OCP\Share\IShare[] $shares */
+ $shares = array_filter($shares, function(\OCP\Share\IShare $share) {
+ return $share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2;
+ });
+ $this->assertCount(1, $shares);
- \OCP\Share::setPermissions('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 17);
+ $share = $shares[0];
+ $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
+ $this->shareManager->updateShare($share);
- $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
+ $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged();
}
diff --git a/apps/files_sharing/tests/groupetagpropagation.php b/apps/files_sharing/tests/groupetagpropagation.php
index 9f6b1e2f720..aaa81135279 100644
--- a/apps/files_sharing/tests/groupetagpropagation.php
+++ b/apps/files_sharing/tests/groupetagpropagation.php
@@ -46,18 +46,36 @@ class GroupEtagPropagation extends PropagationTestCase {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/test/sub');
- $folderInfo = $view1->getFileInfo('/test');
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31);
+
+ $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ '/test',
+ self::TEST_FILES_SHARING_API_USER1,
+ 'group1',
+ \OCP\Constants::PERMISSION_ALL
+ );
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId();
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
- $folderInfo = $view2->getFileInfo('/test');
- $subFolderInfo = $view2->getFileInfo('/test/sub');
- \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31);
- \OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31);
+
+ $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ '/test',
+ self::TEST_FILES_SHARING_API_USER2,
+ 'group2',
+ \OCP\Constants::PERMISSION_ALL
+ );
+ $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ '/test/sub',
+ self::TEST_FILES_SHARING_API_USER2,
+ 'group3',
+ \OCP\Constants::PERMISSION_ALL
+ );
+
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId();
diff --git a/apps/files_sharing/tests/locking.php b/apps/files_sharing/tests/locking.php
index ef8b2bb1cd4..932afe006f9 100644
--- a/apps/files_sharing/tests/locking.php
+++ b/apps/files_sharing/tests/locking.php
@@ -59,7 +59,13 @@ class Locking extends TestCase {
Filesystem::file_put_contents('/foo/bar.txt', 'asd');
$fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
- \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ '/foo/bar.txt',
+ $this->ownerUid,
+ $this->recipientUid,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
$this->loginAsUser($this->recipientUid);
$this->assertTrue(Filesystem::file_exists('bar.txt'));
diff --git a/apps/files_sharing/tests/permissions.php b/apps/files_sharing/tests/permissions.php
index 43a57266851..c1568ceab0a 100644
--- a/apps/files_sharing/tests/permissions.php
+++ b/apps/files_sharing/tests/permissions.php
@@ -33,39 +33,25 @@ use OC\Files\View;
*/
class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
- /**
- * @var Storage
- */
+ /** @var Storage */
private $sharedStorageRestrictedShare;
- /**
- * @var Storage
- */
+ /** @var Storage */
private $sharedCacheRestrictedShare;
- /**
- * @var View
- */
+ /** @var View */
private $secondView;
- /**
- * @var Storage
- */
+ /** @var Storage */
private $ownerStorage;
- /**
- * @var Storage
- */
+ /** @var Storage */
private $sharedStorage;
- /**
- * @var Cache
- */
+ /** @var Cache */
private $sharedCache;
- /**
- * @var Cache
- */
+ /** @var Cache */
private $ownerCache;
protected function setUp() {
@@ -88,12 +74,25 @@ class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
$this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
- \OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 7);
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+
+ $node = $rootFolder->get('container/shareddir');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $this->shareManager->createShare($share);
+
+ $node = $rootFolder->get('container/shareddirrestricted');
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
+ $this->shareManager->createShare($share);
// login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -113,12 +112,10 @@ class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
- \OCP\Share::unshare('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
+ $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER);
+ foreach ($shares as $share) {
+ $this->shareManager->deleteShare($share);
+ }
$this->view->deleteAll('container');
diff --git a/apps/files_sharing/tests/share.php b/apps/files_sharing/tests/share.php
index aad698bcdba..7707cca190f 100644
--- a/apps/files_sharing/tests/share.php
+++ b/apps/files_sharing/tests/share.php
@@ -75,17 +75,21 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
- $fileinfo = $this->view->getFileInfo($this->filename);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31);
-
- $this->assertTrue($result);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- 'testGroup', 31);
+ $share1 = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
- $this->assertTrue($result);
+ $share2 = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ 'testGroup',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
@@ -102,123 +106,9 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
// for user3 nothing should change
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
- }
-
- /**
- * if a file was shared as group share and as individual share they should be grouped
- */
- public function testGroupingOfShares() {
-
- $fileinfo = $this->view->getFileInfo($this->filename);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_READ);
-
- $this->assertTrue($result);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_UPDATE);
-
- $this->assertTrue($result);
-
- self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
-
- $result = \OCP\Share::getItemSharedWith('file', null);
-
- $this->assertTrue(is_array($result));
-
- // test should return exactly one shares created from testCreateShare()
- $this->assertSame(1, count($result));
-
- $share = reset($result);
- $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
-
- \OC\Files\Filesystem::rename($this->filename, $this->filename . '-renamed');
-
- $result = \OCP\Share::getItemSharedWith('file', null);
-
- $this->assertTrue(is_array($result));
-
- // test should return exactly one shares created from testCreateShare()
- $this->assertSame(1, count($result));
-
- $share = reset($result);
- $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
- $this->assertSame($this->filename . '-renamed', $share['file_target']);
-
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
-
- // unshare user share
- $result = \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
-
- self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
-
- $result = \OCP\Share::getItemSharedWith('file', null);
-
- $this->assertTrue(is_array($result));
-
- // test should return the remaining group share
- $this->assertSame(1, count($result));
-
- $share = reset($result);
- // only the group share permissions should be available now
- $this->assertSame(\OCP\Constants::PERMISSION_READ, $share['permissions']);
- $this->assertSame($this->filename . '-renamed', $share['file_target']);
-
- }
-
- /**
- * user1 share file to a group and to a user2 in the same group. Then user2
- * unshares the file from self. Afterwards user1 should no longer see the
- * single user share to user2. If he re-shares the file to user2 the same target
- * then the group share should be used to group the item
- */
- public function testShareAndUnshareFromSelf() {
- $fileinfo = $this->view->getFileInfo($this->filename);
-
- // share the file to group1 (user2 is a member of this group) and explicitely to user2
- \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_ALL);
- \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
-
- // user1 should have to shared files
- $shares = \OCP\Share::getItemsShared('file');
- $this->assertSame(2, count($shares));
-
- // user2 should have two files "welcome.txt" and the shared file,
- // both the group share and the single share of the same file should be
- // grouped to one file
- \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
- $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
- $this->assertSame(2, count($dirContent));
- $this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
-
- // now user2 deletes the share (= unshare from self)
- \OC\Files\Filesystem::unlink($this->filename);
-
- // only welcome.txt should exists
- $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
- $this->assertSame(1, count($dirContent));
- $this->verifyDirContent($dirContent, array('welcome.txt'));
-
- // login as user1...
- \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER1);
-
- // ... now user1 should have only one shared file, the group share
- $shares = \OCP\Share::getItemsShared('file');
- $this->assertSame(1, count($shares));
-
- // user1 shares a gain the file directly to user2
- \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
-
- // user2 should see again welcome.txt and the shared file
- \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
- $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
- $this->assertSame(2, count($dirContent));
- $this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
-
+ $this->shareManager->deleteShare($share1);
+ $this->shareManager->deleteShare($share2);
}
/**
@@ -238,15 +128,23 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
$fileinfo = $this->view->getFileInfo($this->filename);
$folderinfo = $this->view->getFileInfo($this->folder);
- $fileShare = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($fileShare);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
\OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder');
- $folderShare = \OCP\Share::shareItem('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($folderShare);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -261,56 +159,59 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::file_put_contents('test.txt', 'test');
- $fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
-
- $this->assertTrue(
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 23)
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ 'test.txt',
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_GROUP1,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
- $items = \OCP\Share::getItemsSharedWith('file');
- $this->assertSame('/test.txt' ,$items[0]['file_target']);
- $this->assertSame(23, $items[0]['permissions']);
+ $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
+ $share = $shares[0];
+ $this->assertSame('/test.txt' ,$share->getTarget());
+ $this->assertSame(19, $share->getPermissions());
\OC\Files\Filesystem::rename('test.txt', 'new test.txt');
- $items = \OCP\Share::getItemsSharedWith('file');
- $this->assertSame('/new test.txt' ,$items[0]['file_target']);
- $this->assertSame(23, $items[0]['permissions']);
+ $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
+ $share = $shares[0];
+ $this->assertSame('/new test.txt' ,$share->getTarget());
+ $this->assertSame(19, $share->getPermissions());
- $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::setPermissions('file', $items[0]['item_source'], $items[0]['share_type'], $items[0]['share_with'], 3);
+ $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
+ $this->shareManager->updateShare($share);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
- $items = \OCP\Share::getItemsSharedWith('file');
+ $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
+ $share = $shares[0];
- $this->assertSame('/new test.txt' ,$items[0]['file_target']);
- $this->assertSame(3, $items[0]['permissions']);
+ $this->assertSame('/new test.txt' ,$share->getTarget());
+ $this->assertSame(3, $share->getPermissions());
}
/**
* shared files should never have delete permissions
* @dataProvider dataProviderTestFileSharePermissions
*/
- public function testFileSharePermissions($permission, $expectedPermissions) {
-
- $fileinfo = $this->view->getFileInfo($this->filename);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, $permission);
-
- $this->assertTrue($result);
-
- $result = \OCP\Share::getItemShared('file', null);
-
- $this->assertTrue(is_array($result));
-
- // test should return exactly one shares created from testCreateShare()
- $this->assertSame(1, count($result), 'more then one share found');
+ public function testFileSharePermissions($permission, $expectedvalid) {
+
+ $pass = true;
+ try {
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ $permission
+ );
+ } catch (\Exception $e) {
+ $pass = false;
+ }
- $share = reset($result);
- $this->assertSame($expectedPermissions, $share['permissions']);
+ $this->assertEquals($expectedvalid, $pass);
}
public function dataProviderTestFileSharePermissions() {
@@ -321,22 +222,23 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
$permission6 = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
return array(
- array($permission1, \OCP\Constants::PERMISSION_ALL & ~\OCP\Constants::PERMISSION_DELETE),
- array($permission3, $permission3),
- array($permission4, $permission4),
- array($permission5, $permission3),
- array($permission6, $permission4),
+ array($permission1, false),
+ array($permission3, true),
+ array($permission4, true),
+ array($permission5, false),
+ array($permission6, false),
);
}
public function testFileOwner() {
- $fileinfo = $this->view->getFileInfo($this->filename);
-
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
-
- $this->assertTrue($result);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ
+ );
$this->loginHelper(\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
@@ -344,135 +246,4 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
$this->assertSame(\Test_Files_Sharing::TEST_FILES_SHARING_API_USER1, $info->getOwner()->getUID());
}
-
- /**
- * @dataProvider dataProviderGetUsersSharingFile
- *
- * @param string $groupName name of group to share with
- * @param bool $includeOwner whether to include the owner in the result
- * @param bool $includePaths whether to include paths in the result
- * @param array $expectedResult expected result of the API call
- */
- public function testGetUsersSharingFile($groupName, $includeOwner, $includePaths, $expectedResult) {
-
- $fileinfo = $this->view->getFileInfo($this->folder);
-
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- $groupName, \OCP\Constants::PERMISSION_READ);
- $this->assertTrue($result);
-
- // public share
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK,
- null, \OCP\Constants::PERMISSION_READ);
- $this->assertNotNull($result); // returns the token!
-
- // owner renames after sharing
- $this->view->rename($this->folder, $this->folder . '_owner_renamed');
-
- self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
-
- $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
- $user2View->rename($this->folder, $this->folder . '_renamed');
-
- $ownerPath = $this->folder . '_owner_renamed';
- $owner = self::TEST_FILES_SHARING_API_USER1;
-
- $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, $includeOwner, $includePaths);
-
- // sort users to make sure it matches
- if ($includePaths) {
- ksort($result);
- } else {
- sort($result['users']);
- }
-
- $this->assertEquals(
- $expectedResult,
- $result
- );
- }
-
- public function dataProviderGetUsersSharingFile() {
- // note: "group" contains user1 (the owner), user2 and user3
- // and self::TEST_FILES_SHARING_API_GROUP1 contains only user2
- return [
- // share with group that contains owner
- [
- 'group',
- false,
- false,
- [
- 'users' =>
- [
- // because user1 was in group
- self::TEST_FILES_SHARING_API_USER1,
- self::TEST_FILES_SHARING_API_USER2,
- self::TEST_FILES_SHARING_API_USER3,
- ],
- 'public' => true,
- 'remote' => false,
- ],
- ],
- // share with group that does not contain owner
- [
- self::TEST_FILES_SHARING_API_GROUP1,
- false,
- false,
- [
- 'users' =>
- [
- self::TEST_FILES_SHARING_API_USER2,
- ],
- 'public' => true,
- 'remote' => false,
- ],
- ],
- // share with group that does not contain owner, include owner
- [
- self::TEST_FILES_SHARING_API_GROUP1,
- true,
- false,
- [
- 'users' =>
- [
- self::TEST_FILES_SHARING_API_USER1,
- self::TEST_FILES_SHARING_API_USER2,
- ],
- 'public' => true,
- 'remote' => false,
- ],
- ],
- // include paths, with owner
- [
- 'group',
- true,
- true,
- [
- self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME . '_owner_renamed',
- self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME . '_renamed',
- self::TEST_FILES_SHARING_API_USER3 => self::TEST_FOLDER_NAME,
- ],
- ],
- // include paths, group without owner
- [
- self::TEST_FILES_SHARING_API_GROUP1,
- false,
- true,
- [
- self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME. '_renamed',
- ],
- ],
- // include paths, include owner, group without owner
- [
- self::TEST_FILES_SHARING_API_GROUP1,
- true,
- true,
- [
- self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME . '_owner_renamed',
- self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME . '_renamed',
- ],
- ],
- ];
- }
-
}
diff --git a/apps/files_sharing/tests/sharedmount.php b/apps/files_sharing/tests/sharedmount.php
index e01deeb60f4..48040ab8dc9 100644
--- a/apps/files_sharing/tests/sharedmount.php
+++ b/apps/files_sharing/tests/sharedmount.php
@@ -49,8 +49,12 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
protected function tearDown() {
if ($this->view) {
- $this->view->unlink($this->folder);
- $this->view->unlink($this->filename);
+ if ($this->view->file_exists($this->folder)) {
+ $this->view->unlink($this->folder);
+ }
+ if ($this->view->file_exists($this->filename)) {
+ $this->view->unlink($this->filename);
+ }
}
parent::tearDown();
@@ -59,59 +63,46 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
/**
* test if the mount point moves up if the parent folder no longer exists
*/
- function testShareMountLoseParentFolder() {
+ public function testShareMountLoseParentFolder() {
// share to user
- $fileinfo = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
-
- $statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?";
- $query = \OCP\DB::prepare($statement);
- $arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2);
- $query->execute($arguments);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL);
- $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
- $result = $query->execute();
+ $share->setTarget('/foo/bar' . $this->folder);
+ $this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
- $shares = $result->fetchAll();
-
- $this->assertSame(1, count($shares));
-
- $share = reset($shares);
- $this->assertSame('/foo/bar' . $this->folder, $share['file_target']);
+ $share = $this->shareManager->getShareById($share->getFullId());
+ $this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
-
// share should have moved up
- $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
- $result = $query->execute();
-
- $shares = $result->fetchAll();
-
- $this->assertSame(1, count($shares));
-
- $share = reset($shares);
- $this->assertSame($this->folder, $share['file_target']);
+ $share = $this->shareManager->getShareById($share->getFullId());
+ $this->assertSame($this->folder, $share->getTarget());
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($share);
$this->view->unlink($this->folder);
}
/**
* @medium
*/
- function testDeleteParentOfMountPoint() {
-
+ public function testDeleteParentOfMountPoint() {
// share to user
- $fileinfo = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
-
- $this->assertTrue($result);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -143,10 +134,14 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
$this->view->unlink($this->folder);
}
- function testMoveSharedFile() {
- $fileinfo = $this->view->getFileInfo($this->filename);
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ public function testMoveSharedFile() {
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -166,22 +161,27 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
//cleanup
- \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($share);
}
/**
* share file with a group if a user renames the file the filename should not change
* for the other users
*/
- function testMoveGroupShare () {
+ public function testMoveGroupShare () {
\OC_Group::createGroup('testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$fileinfo = $this->view->getFileInfo($this->filename);
- $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- "testGroup", 31);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ 'testGroup',
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -202,7 +202,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
+ $this->shareManager->deleteShare($share);
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
@@ -214,7 +214,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
* @param string $expectedResult
* @param bool $exception if a exception is expected
*/
- function testStripUserFilesPath($path, $expectedResult, $exception) {
+ public function testStripUserFilesPath($path, $expectedResult, $exception) {
$testClass = new DummyTestClassSharedMount(null, null);
try {
$result = $testClass->stripUserFilesPathDummy($path);
@@ -228,7 +228,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
}
}
- function dataProviderTestStripUserFilesPath() {
+ public function dataProviderTestStripUserFilesPath() {
return array(
array('/user/files/foo.txt', '/foo.txt', false),
array('/user/files/folder/foo.txt', '/folder/foo.txt', false),
@@ -239,7 +239,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
);
}
- function dataPermissionMovedGroupShare() {
+ public function dataPermissionMovedGroupShare() {
$data = [];
$powerset = function($permissions) {
@@ -256,7 +256,6 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
//Generate file permissions
$permissions = [
\OCP\Constants::PERMISSION_UPDATE,
- \OCP\Constants::PERMISSION_CREATE,
\OCP\Constants::PERMISSION_SHARE,
];
@@ -321,54 +320,45 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
// Share item with group
- $fileinfo = $this->view->getFileInfo($path);
- $this->assertTrue(
- \OCP\Share::shareItem($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", $beforePerm)
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ $path,
+ self::TEST_FILES_SHARING_API_USER1,
+ 'testGroup',
+ $beforePerm
);
// Login as user 2 and verify the item exists
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($path));
- $result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
- $this->assertNotEmpty($result);
- $this->assertEquals($beforePerm, $result['permissions']);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
+ $this->assertEquals($beforePerm, $result->getPermissions());
// Now move the item forcing a new entry in the share table
\OC\Files\Filesystem::rename($path, "newPath");
$this->assertTrue(\OC\Files\Filesystem::file_exists('newPath'));
$this->assertFalse(\OC\Files\Filesystem::file_exists($path));
- // Login as user 1 again and change permissions
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $this->assertTrue(
- \OCP\Share::setPermissions($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", $afterPerm)
- );
+ // change permissions
+ $share->setPermissions($afterPerm);
+ $this->shareManager->updateShare($share);
// Login as user 3 and verify that the permissions are changed
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
- $result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER3);
$this->assertNotEmpty($result);
- $this->assertEquals($afterPerm, $result['permissions']);
- $groupShareId = $result['id'];
+ $this->assertEquals($afterPerm, $result->getPermissions());
// Login as user 2 and verify that the permissions are changed
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
- $result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
$this->assertNotEmpty($result);
- $this->assertEquals($afterPerm, $result['permissions']);
- $this->assertNotEquals($groupShareId, $result['id']);
-
- // Also verify in the DB
- $statement = "SELECT `permissions` FROM `*PREFIX*share` WHERE `id`=?";
- $query = \OCP\DB::prepare($statement);
- $result = $query->execute([$result['id']]);
- $shares = $result->fetchAll();
- $this->assertCount(1, $shares);
- $this->assertEquals($afterPerm, $shares[0]['permissions']);
+ $this->assertEquals($afterPerm, $result->getPermissions());
+ $this->assertEquals('/newPath', $result->getTarget());
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
+ $this->shareManager->deleteShare($share);
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
@@ -388,66 +378,44 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
// Share item with group
$fileinfo = $this->view->getFileInfo($this->folder);
- $this->assertTrue(
- \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_READ)
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ 'testGroup',
+ \OCP\Constants::PERMISSION_READ
);
// Login as user 2 and verify the item exists
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
- $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
$this->assertNotEmpty($result);
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']);
+ $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions());
// Delete the share
$this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
// Verify we do not get a share
- $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
- $this->assertEmpty($result);
-
- // Verify that the permission is correct in the DB
- $qb = $connection->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))
- ->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))
- ->setParameter(':fileSource', $fileinfo['fileid'])
- ->setParameter(':shareType', 2);
- $res = $qb->execute()->fetchAll();
-
- $this->assertCount(1, $res);
- $this->assertEquals(0, $res[0]['permissions']);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
+ $this->assertEquals(0, $result->getPermissions());
// Login as user 1 again and change permissions
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $this->assertTrue(
- \OCP\Share::setPermissions('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_ALL)
- );
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = $this->shareManager->updateShare($share);
// Login as user 2 and verify
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
- $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
- $this->assertEmpty($result);
+ $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
+ $this->assertEquals(0, $result->getPermissions());
- $connection = \OC::$server->getDatabaseConnection();
- $qb = $connection->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))
- ->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))
- ->setParameter(':fileSource', $fileinfo['fileid'])
- ->setParameter(':shareType', 2);
- $res = $qb->execute()->fetchAll();
-
- $this->assertCount(1, $res);
- $this->assertEquals(0, $res[0]['permissions']);
+ $this->shareManager->deleteShare($share);
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php
index 63f4334103f..19edc44f9b4 100644
--- a/apps/files_sharing/tests/sharedstorage.php
+++ b/apps/files_sharing/tests/sharedstorage.php
@@ -50,8 +50,12 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
protected function tearDown() {
if ($this->view) {
- $this->view->unlink($this->folder);
- $this->view->unlink($this->filename);
+ if ($this->view->file_exists($this->folder)) {
+ $this->view->unlink($this->folder);
+ }
+ if ($this->view->file_exists($this->filename)) {
+ $this->view->unlink($this->filename);
+ }
}
\OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
@@ -64,14 +68,16 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
*
* @medium
*/
- function testParentOfMountPointIsGone() {
+ public function testParentOfMountPointIsGone() {
// share to user
- $fileinfo = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
-
- $this->assertTrue($result);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -107,14 +113,17 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
/**
* @medium
*/
- function testRenamePartFile() {
+ public function testRenamePartFile() {
// share to user
- $fileinfo = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
- $this->assertTrue($result);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -139,26 +148,30 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
//cleanup
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($share);
}
public function testFilesize() {
-
- $fileinfoFolder = $this->view->getFileInfo($this->folder);
- $fileinfoFile = $this->view->getFileInfo($this->filename);
-
$folderSize = $this->view->filesize($this->folder);
$file1Size = $this->view->filesize($this->folder . $this->filename);
$file2Size = $this->view->filesize($this->filename);
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($result);
+ $share1 = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
+
+ $share2 = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
- $result = \OCP\Share::shareItem('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($result);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -168,21 +181,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertSame($file2Size, \OC\Files\Filesystem::filesize($this->filename));
//cleanup
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
- $result = \OCP\Share::unshare('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share1);
+ $this->shareManager->deleteShare($share2);
}
- function testGetPermissions() {
- $fileinfoFolder = $this->view->getFileInfo($this->folder);
+ public function testGetPermissions() {
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ
+ );
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 1);
- $this->assertTrue($result);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -201,18 +212,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
//cleanup
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
}
public function testFopenWithReadOnlyPermission() {
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
- $fileinfoFolder = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ);
- $this->assertTrue($result);
+
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -232,18 +244,20 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
//cleanup
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
}
public function testFopenWithCreateOnlyPermission() {
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
$fileinfoFolder = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE);
- $this->assertTrue($result);
+
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -284,11 +298,14 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
public function testFopenWithUpdateOnlyPermission() {
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
- $fileinfoFolder = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
- $this->assertTrue($result);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -322,18 +339,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
//cleanup
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
}
public function testFopenWithDeleteOnlyPermission() {
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
- $fileinfoFolder = $this->view->getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE);
- $this->assertTrue($result);
+
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -353,23 +371,28 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
//cleanup
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
}
- function testMountSharesOtherUser() {
- $folderInfo = $this->view->getFileInfo($this->folder);
- $fileInfo = $this->view->getFileInfo($this->filename);
+ public function testMountSharesOtherUser() {
$rootView = new \OC\Files\View('');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
// share 2 different files with 2 different users
- \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER3, 31);
+ $share1 = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
+ $share2 = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->filename,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER3,
+ \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
@@ -387,15 +410,21 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
+
+ $this->shareManager->deleteShare($share1);
+ $this->shareManager->deleteShare($share2);
}
public function testCopyFromStorage() {
- $folderInfo = $this->view->getFileInfo($this->folder);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- // share 2 different files with 2 different users
- \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -416,15 +445,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
+ $this->shareManager->deleteShare($share);
}
public function testMoveFromStorage() {
- $folderInfo = $this->view->getFileInfo($this->folder);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- // share 2 different files with 2 different users
- \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -445,31 +478,40 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
+ $this->shareManager->deleteShare($share);
}
public function testNameConflict() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('foo');
- $folderInfo1 = $view1->getFileInfo('foo');
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
$view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
$view3->mkdir('foo');
- $folderInfo2 = $view3->getFileInfo('foo');
// share a folder with the same name from two different users to the same user
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- \OCP\Share::shareItem('folder', $folderInfo1['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- self::TEST_FILES_SHARING_API_GROUP1, 31);
+ $share1 = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ 'foo',
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_GROUP1,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
- \OCP\Share::shareItem('folder', $folderInfo2['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
- self::TEST_FILES_SHARING_API_GROUP1, 31);
+ $share2 = $this->share(
+ \OCP\Share::SHARE_TYPE_GROUP,
+ 'foo',
+ self::TEST_FILES_SHARING_API_USER3,
+ self::TEST_FILES_SHARING_API_GROUP1,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -482,7 +524,9 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
/** @var \OC\Files\Storage\Shared $storage */
$storage = $mount->getStorage();
- $source = $storage->getFile('');
- $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $source['uid_owner']);
+ $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
+
+ $this->shareManager->deleteShare($share1);
+ $this->shareManager->deleteShare($share2);
}
}
diff --git a/apps/files_sharing/tests/sizepropagation.php b/apps/files_sharing/tests/sizepropagation.php
index 7b7884f3f96..d4062e3a38c 100644
--- a/apps/files_sharing/tests/sizepropagation.php
+++ b/apps/files_sharing/tests/sizepropagation.php
@@ -43,9 +43,13 @@ class SizePropagation extends TestCase {
$ownerView->mkdir('/sharedfolder/subfolder');
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
- $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
- $this->assertInstanceOf('\OC\Files\FileInfo', $sharedFolderInfo);
- \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ '/sharedfolder',
+ self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER1,
+ \OCP\Constants::PERMISSION_ALL
+ );
$ownerRootInfo = $ownerView->getFileInfo('', false);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
@@ -76,9 +80,13 @@ class SizePropagation extends TestCase {
$ownerView->mkdir('/sharedfolder/subfolder');
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
- $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
- $this->assertInstanceOf('\OC\Files\FileInfo', $sharedFolderInfo);
- \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ '/sharedfolder',
+ self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER1,
+ \OCP\Constants::PERMISSION_ALL
+ );
$ownerRootInfo = $ownerView->getFileInfo('', false);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php
index 3c291f4167c..0950c2a62f5 100644
--- a/apps/files_sharing/tests/testcase.php
+++ b/apps/files_sharing/tests/testcase.php
@@ -59,6 +59,11 @@ abstract class TestCase extends \Test\TestCase {
public $folder;
public $subfolder;
+ /** @var \OCP\Share\IManager */
+ protected $shareManager;
+ /** @var \OCP\Files\IRootFolder */
+ protected $rootFolder;
+
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
@@ -96,7 +101,6 @@ abstract class TestCase extends \Test\TestCase {
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1);
\OC_Group::useBackend($groupBackend);
-
}
protected function setUp() {
@@ -107,6 +111,9 @@ abstract class TestCase extends \Test\TestCase {
$this->data = 'foobar';
$this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
+
+ $this->shareManager = \OC::$server->getShareManager();
+ $this->rootFolder = \OC::$server->getRootFolder();
}
protected function tearDown() {
@@ -201,4 +208,26 @@ abstract class TestCase extends \Test\TestCase {
}
+ /**
+ * @param int $type The share type
+ * @param string $path The path to share relative to $initiators root
+ * @param string $initiator
+ * @param string $recipient
+ * @param int $permissions
+ * @return \OCP\Share\IShare
+ */
+ protected function share($type, $path, $initiator, $recipient, $permissions) {
+ $userFolder = $this->rootFolder->getUserFolder($initiator);
+ $node = $userFolder->get($path);
+
+ $share = $this->shareManager->newShare();
+ $share->setShareType($type)
+ ->setSharedWith($recipient)
+ ->setSharedBy($initiator)
+ ->setNode($node)
+ ->setPermissions($permissions);
+ $share = $this->shareManager->createShare($share);
+
+ return $share;
+ }
}
diff --git a/apps/files_sharing/tests/unsharechildren.php b/apps/files_sharing/tests/unsharechildren.php
index 1968007be4e..6104dc98080 100644
--- a/apps/files_sharing/tests/unsharechildren.php
+++ b/apps/files_sharing/tests/unsharechildren.php
@@ -78,14 +78,19 @@ class UnshareChildren extends TestCase {
$fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($result);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// one folder should be shared with the user
- $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
- $this->assertSame(1, count($sharedFolders));
+ $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
+ $this->assertCount(1, $shares);
// move shared folder to 'localDir'
\OC\Files\Filesystem::mkdir('localDir');
@@ -97,8 +102,8 @@ class UnshareChildren extends TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// after the parent directory was deleted the share should be unshared
- $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
- $this->assertTrue(empty($sharedFolders));
+ $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
+ $this->assertEmpty($shares);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
diff --git a/apps/files_sharing/tests/updater.php b/apps/files_sharing/tests/updater.php
index 67c1642cdd0..53e7fc47665 100644
--- a/apps/files_sharing/tests/updater.php
+++ b/apps/files_sharing/tests/updater.php
@@ -75,7 +75,13 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
- \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
+ $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
@@ -152,9 +158,14 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
$etagBeforeShareDir = $beforeShareDir->getEtag();
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($result);
+
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -173,8 +184,7 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
// cleanup
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
$config->setSystemValue('share_folder', $oldShareFolder);
}
@@ -185,8 +195,14 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
function testRename() {
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
- $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
- $this->assertTrue($result);
+
+ $share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ $this->folder,
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -210,9 +226,7 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
// cleanup
- $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
- $this->assertTrue($result);
+ $this->shareManager->deleteShare($share);
}
}
diff --git a/apps/files_sharing/tests/watcher.php b/apps/files_sharing/tests/watcher.php
index 247fb59f351..19e1bc0b615 100644
--- a/apps/files_sharing/tests/watcher.php
+++ b/apps/files_sharing/tests/watcher.php
@@ -32,33 +32,27 @@
*/
class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
- /**
- * @var \OC\Files\Storage\Storage
- */
+ /** @var \OC\Files\Storage\Storage */
private $ownerStorage;
- /**
- * @var \OC\Files\Cache\Cache
- */
+ /** @var \OC\Files\Cache\Cache */
private $ownerCache;
- /**
- * @var \OC\Files\Storage\Storage
- */
+ /** @var \OC\Files\Storage\Storage */
private $sharedStorage;
- /**
- * @var \OC\Files\Cache\Cache
- */
+ /** @var \OC\Files\Cache\Cache */
private $sharedCache;
+ /** @var \OCP\Share\IShare */
+ private $_share;
+
protected function setUp() {
parent::setUp();
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
// prepare user1's dir structure
- $textData = "dummy file data\n";
$this->view->mkdir('container');
$this->view->mkdir('container/shareddir');
$this->view->mkdir('container/shareddir/subdir');
@@ -68,9 +62,13 @@ class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
$this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2, 31);
+ $this->_share = $this->share(
+ \OCP\Share::SHARE_TYPE_USER,
+ 'container/shareddir',
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
// login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
@@ -89,9 +87,7 @@ class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
if ($this->view) {
- $fileinfo = $this->view->getFileInfo('container/shareddir');
- \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- self::TEST_FILES_SHARING_API_USER2);
+ $this->shareManager->deleteShare($this->_share);
$this->view->deleteAll('container');
diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php
index afc07ff36c8..5c631770da3 100644
--- a/apps/files_trashbin/tests/storage.php
+++ b/apps/files_trashbin/tests/storage.php
@@ -261,9 +261,14 @@ class Storage extends \Test\TestCase {
$recipientUser = $this->getUniqueId('recipient_');
\OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
- $fileinfo = $this->userView->getFileInfo('share');
- $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- $recipientUser, 31));
+ $node = \OC::$server->getUserFolder($this->user)->get('share');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy($this->user)
+ ->setSharedWith($recipientUser)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ \OC::$server->getShareManager()->createShare($share);
$this->loginAsUser($recipientUser);
@@ -309,9 +314,14 @@ class Storage extends \Test\TestCase {
$recipientUser = $this->getUniqueId('recipient_');
\OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
- $fileinfo = $this->userView->getFileInfo('share');
- $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
- $recipientUser, 31));
+ $node = \OC::$server->getUserFolder($this->user)->get('share');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy($this->user)
+ ->setSharedWith($recipientUser)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ \OC::$server->getShareManager()->createShare($share);
$this->loginAsUser($recipientUser);
diff --git a/apps/files_trashbin/tests/trashbin.php b/apps/files_trashbin/tests/trashbin.php
index 8d616b6e8e2..7087da37266 100644
--- a/apps/files_trashbin/tests/trashbin.php
+++ b/apps/files_trashbin/tests/trashbin.php
@@ -211,9 +211,14 @@ class Test_Trashbin extends \Test\TestCase {
\OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
//share user1-4.txt with user2
- $fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
- $result = \OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_TRASHBIN_USER2, 31);
- $this->assertTrue($result);
+ $node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setNode($node)
+ ->setSharedBy(self::TEST_TRASHBIN_USER1)
+ ->setSharedWith(self::TEST_TRASHBIN_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ \OC::$server->getShareManager()->createShare($share);
// delete them so that they end up in the trash bin
\OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index 9d0ffb87946..b8e68cfadf7 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -297,8 +297,6 @@ class Test_Files_Versioning extends \Test\TestCase {
\OC\Files\Filesystem::mkdir('folder1/folder2');
\OC\Files\Filesystem::file_put_contents("folder1/test.txt", "test file");
- $fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
-
$t1 = time();
// second version is two weeks older, this way we make sure that no
// version will be expired
@@ -314,7 +312,14 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
- \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
+ $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy(self::TEST_VERSIONS_USER)
+ ->setSharedWith(self::TEST_VERSIONS_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = \OC::$server->getShareManager()->createShare($share);
self::loginHelper(self::TEST_VERSIONS_USER2);
@@ -332,6 +337,8 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->assertTrue($this->rootView->file_exists($v1Renamed));
$this->assertTrue($this->rootView->file_exists($v2Renamed));
+
+ \OC::$server->getShareManager()->deleteShare($share);
}
public function testMoveFolder() {
@@ -373,13 +380,14 @@ class Test_Files_Versioning extends \Test\TestCase {
\OC\Files\Filesystem::mkdir('folder1');
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
- \OCP\Share::shareItem(
- 'folder',
- $fileInfo['fileid'],
- \OCP\Share::SHARE_TYPE_USER,
- self::TEST_VERSIONS_USER2,
- \OCP\Constants::PERMISSION_ALL
- );
+ $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy(self::TEST_VERSIONS_USER)
+ ->setSharedWith(self::TEST_VERSIONS_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = \OC::$server->getShareManager()->createShare($share);
self::loginHelper(self::TEST_VERSIONS_USER2);
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
@@ -413,20 +421,22 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->assertTrue($this->rootView->file_exists($v1Renamed));
$this->assertTrue($this->rootView->file_exists($v2Renamed));
+
+ \OC::$server->getShareManager()->deleteShare($share);
}
public function testMoveFolderIntoSharedFolderAsRecipient() {
\OC\Files\Filesystem::mkdir('folder1');
- $fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
- \OCP\Share::shareItem(
- 'folder',
- $fileInfo['fileid'],
- \OCP\Share::SHARE_TYPE_USER,
- self::TEST_VERSIONS_USER2,
- \OCP\Constants::PERMISSION_ALL
- );
+ $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy(self::TEST_VERSIONS_USER)
+ ->setSharedWith(self::TEST_VERSIONS_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = \OC::$server->getShareManager()->createShare($share);
self::loginHelper(self::TEST_VERSIONS_USER2);
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
@@ -462,14 +472,14 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->assertTrue($this->rootView->file_exists($v1Renamed));
$this->assertTrue($this->rootView->file_exists($v2Renamed));
+
+ \OC::$server->getShareManager()->deleteShare($share);
}
public function testRenameSharedFile() {
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
- $fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
-
$t1 = time();
// second version is two weeks older, this way we make sure that no
// version will be expired
@@ -486,7 +496,14 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
+ $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy(self::TEST_VERSIONS_USER)
+ ->setSharedWith(self::TEST_VERSIONS_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
+ $share = \OC::$server->getShareManager()->createShare($share);
self::loginHelper(self::TEST_VERSIONS_USER2);
@@ -504,6 +521,8 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->assertFalse($this->rootView->file_exists($v1Renamed));
$this->assertFalse($this->rootView->file_exists($v2Renamed));
+
+ \OC::$server->getShareManager()->deleteShare($share);
}
public function testCopy() {
@@ -744,15 +763,15 @@ class Test_Files_Versioning extends \Test\TestCase {
\OC\Files\Filesystem::mkdir('folder');
\OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
- $fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
-
- \OCP\Share::shareItem(
- 'folder',
- $fileInfo['fileid'],
- \OCP\Share::SHARE_TYPE_USER,
- self::TEST_VERSIONS_USER2,
- \OCP\Constants::PERMISSION_ALL
- );
+
+ $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setNode($node)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedBy(self::TEST_VERSIONS_USER)
+ ->setSharedWith(self::TEST_VERSIONS_USER2)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share = \OC::$server->getShareManager()->createShare($share);
$this->loginAsUser(self::TEST_VERSIONS_USER2);
@@ -760,6 +779,8 @@ class Test_Files_Versioning extends \Test\TestCase {
\OC\Files\Filesystem::getView(),
'folder/test.txt'
);
+
+ \OC::$server->getShareManager()->deleteShare($share);
}
/**
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 1ec25750cfe..dee9e0cdd21 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -237,6 +237,17 @@ class Manager implements IManager {
if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
throw new \InvalidArgumentException('Shares need at least read permissions');
}
+
+ if ($share->getNode() instanceof \OCP\Files\File) {
+ if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
+ $message_t = $this->l->t('Files can\'t be shared with delete permissions');
+ throw new GenericShareException($message_t);
+ }
+ if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
+ $message_t = $this->l->t('Files can\'t be shared with create permissions');
+ throw new GenericShareException($message_t);
+ }
+ }
}
/**
@@ -505,6 +516,24 @@ class Manager implements IManager {
$this->generalCreateChecks($share);
+ // Verify if there are any issues with the path
+ $this->pathCreateChecks($share->getNode());
+
+ /*
+ * On creation of a share the owner is always the owner of the path
+ * Except for mounted federated shares.
+ */
+ $storage = $share->getNode()->getStorage();
+ if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
+ $parent = $share->getNode()->getParent();
+ while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
+ $parent = $parent->getParent();
+ }
+ $share->setShareOwner($parent->getOwner()->getUID());
+ } else {
+ $share->setShareOwner($share->getNode()->getOwner()->getUID());
+ }
+
//Verify share type
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$this->userCreateChecks($share);
@@ -538,24 +567,6 @@ class Manager implements IManager {
}
}
- // Verify if there are any issues with the path
- $this->pathCreateChecks($share->getNode());
-
- /*
- * On creation of a share the owner is always the owner of the path
- * Except for mounted federated shares.
- */
- $storage = $share->getNode()->getStorage();
- if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
- $parent = $share->getNode()->getParent();
- while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
- $parent = $parent->getParent();
- }
- $share->setShareOwner($parent->getOwner()->getUID());
- } else {
- $share->setShareOwner($share->getNode()->getOwner()->getUID());
- }
-
// Cannot share with the owner
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $share->getShareOwner()) {
@@ -818,7 +829,7 @@ class Manager implements IManager {
* @param string $recipientId
*/
public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
- list($providerId, ) = $this->splitFullId($share->getId());
+ list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);
$provider->deleteFromSelf($share, $recipientId);
@@ -844,7 +855,7 @@ class Manager implements IManager {
}
}
- list($providerId, ) = $this->splitFullId($share->getId());
+ list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);
$provider->move($share, $recipientId);
diff --git a/lib/private/files/cache/wrapper/cachejail.php b/lib/private/files/cache/wrapper/cachejail.php
index 868e63cdf81..88b0f23a1fc 100644
--- a/lib/private/files/cache/wrapper/cachejail.php
+++ b/lib/private/files/cache/wrapper/cachejail.php
@@ -281,4 +281,20 @@ class CacheJail extends CacheWrapper {
$path = $this->cache->getPathById($id);
return $this->getJailedPath($path);
}
+
+ /**
+ * Move a file or folder in the cache
+ *
+ * Note that this should make sure the entries are removed from the source cache
+ *
+ * @param \OCP\Files\Cache\ICache $sourceCache
+ * @param string $sourcePath
+ * @param string $targetPath
+ */
+ public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
+ if ($sourceCache === $this) {
+ return $this->move($sourcePath, $targetPath);
+ }
+ return $this->cache->moveFromCache($sourceCache, $sourcePath, $targetPath);
+ }
}
diff --git a/lib/private/files/config/cachedmountinfo.php b/lib/private/files/config/cachedmountinfo.php
index 2993c979a7f..ce75cb66896 100644
--- a/lib/private/files/config/cachedmountinfo.php
+++ b/lib/private/files/config/cachedmountinfo.php
@@ -30,22 +30,22 @@ class CachedMountInfo implements ICachedMountInfo {
/**
* @var IUser
*/
- private $user;
+ protected $user;
/**
* @var int
*/
- private $storageId;
+ protected $storageId;
/**
* @var int
*/
- private $rootId;
+ protected $rootId;
/**
* @var string
*/
- private $mountPoint;
+ protected $mountPoint;
/**
* CachedMountInfo constructor.
@@ -88,9 +88,9 @@ class CachedMountInfo implements ICachedMountInfo {
*/
public function getMountPointNode() {
// TODO injection etc
- Filesystem::initMountPoints($this->user->getUID());
- $userNode = \OC::$server->getUserFolder($this->user->getUID());
- $nodes = $userNode->getById($this->rootId);
+ Filesystem::initMountPoints($this->getUser()->getUID());
+ $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
+ $nodes = $userNode->getById($this->getRootId());
if (count($nodes) > 0) {
return $nodes[0];
} else {
diff --git a/lib/private/files/config/lazystoragemountinfo.php b/lib/private/files/config/lazystoragemountinfo.php
new file mode 100644
index 00000000000..654c5b2b23e
--- /dev/null
+++ b/lib/private/files/config/lazystoragemountinfo.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Files\Config;
+
+use OC\Files\Filesystem;
+use OCP\Files\Config\ICachedMountInfo;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node;
+use OCP\IUser;
+
+class LazyStorageMountInfo extends CachedMountInfo {
+ /** @var IMountPoint */
+ private $mount;
+
+ /**
+ * CachedMountInfo constructor.
+ *
+ * @param IUser $user
+ * @param IMountPoint $mount
+ */
+ public function __construct(IUser $user, IMountPoint $mount) {
+ $this->user = $user;
+ $this->mount = $mount;
+ }
+
+ /**
+ * @return int the numeric storage id of the mount
+ */
+ public function getStorageId() {
+ if (!$this->storageId) {
+ $this->storageId = $this->mount->getStorage()->getStorageCache()->getNumericId();
+ }
+ return parent::getStorageId();
+ }
+
+ /**
+ * @return int the fileid of the root of the mount
+ */
+ public function getRootId() {
+ if (!$this->rootId) {
+ $this->rootId = $this->mount->getStorageRootId();
+ }
+ return parent::getRootId();
+ }
+
+ /**
+ * @return string the mount point of the mount for the user
+ */
+ public function getMountPoint() {
+ if (!$this->mountPoint) {
+ $this->mountPoint = $this->mount->getMountPoint();
+ }
+ return parent::getMountPoint();
+ }
+}
diff --git a/lib/private/files/config/usermountcache.php b/lib/private/files/config/usermountcache.php
index 78b19972787..05ca146f4be 100644
--- a/lib/private/files/config/usermountcache.php
+++ b/lib/private/files/config/usermountcache.php
@@ -80,18 +80,11 @@ class UserMountCache implements IUserMountCache {
});
/** @var ICachedMountInfo[] $newMounts */
$newMounts = array_map(function (IMountPoint $mount) use ($user) {
- $storage = $mount->getStorage();
- if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
- $rootId = (int)$storage->getShare()['file_source'];
- } else {
- $rootId = (int)$storage->getCache()->getId('');
- }
- $storageId = (int)$storage->getStorageCache()->getNumericId();
// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
- if ($rootId === -1) {
+ if ($mount->getStorageRootId() === -1) {
return null;
} else {
- return new CachedMountInfo($user, $storageId, $rootId, $mount->getMountPoint());
+ return new LazyStorageMountInfo($user, $mount);
}
}, $mounts);
$newMounts = array_values(array_filter($newMounts));
diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php
index b606c625cb1..7b9294fc1e0 100644
--- a/lib/private/files/mount/mountpoint.php
+++ b/lib/private/files/mount/mountpoint.php
@@ -239,4 +239,13 @@ class MountPoint implements IMountPoint {
public function getOptions() {
return $this->mountOptions;
}
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ */
+ public function getStorageRootId() {
+ return (int)$this->getStorage()->getCache()->getId('');
+ }
}
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 85c2e1c6700..3a811b312c6 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -313,20 +313,20 @@ abstract class Common implements Storage, ILockingStorage {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->cache)) {
- $this->cache = new Cache($storage);
+ if (!isset($storage->cache)) {
+ $storage->cache = new Cache($storage);
}
- return $this->cache;
+ return $storage->cache;
}
public function getScanner($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->scanner)) {
- $this->scanner = new Scanner($storage);
+ if (!isset($storage->scanner)) {
+ $storage->scanner = new Scanner($storage);
}
- return $this->scanner;
+ return $storage->scanner;
}
public function getWatcher($path = '', $storage = null) {
@@ -351,20 +351,20 @@ abstract class Common implements Storage, ILockingStorage {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->propagator)) {
- $this->propagator = new Propagator($storage);
+ if (!isset($storage->propagator)) {
+ $storage->propagator = new Propagator($storage);
}
- return $this->propagator;
+ return $storage->propagator;
}
public function getUpdater($storage = null) {
if (!$storage) {
$storage = $this;
}
- if (!isset($this->updater)) {
- $this->updater = new Updater($storage);
+ if (!isset($storage->updater)) {
+ $storage->updater = new Updater($storage);
}
- return $this->updater;
+ return $storage->updater;
}
public function getStorageCache($storage = null) {
diff --git a/lib/private/files/storage/wrapper/jail.php b/lib/private/files/storage/wrapper/jail.php
index e5f5ab90359..e8063f670c5 100644
--- a/lib/private/files/storage/wrapper/jail.php
+++ b/lib/private/files/storage/wrapper/jail.php
@@ -47,7 +47,7 @@ class Jail extends Wrapper {
$this->rootPath = $arguments['root'];
}
- protected function getSourcePath($path) {
+ public function getSourcePath($path) {
if ($path === '') {
return $this->rootPath;
} else {
@@ -417,6 +417,14 @@ class Jail extends Wrapper {
/**
* @param string $path
+ * @return array
+ */
+ public function getMetaData($path) {
+ return $this->storage->getMetaData($this->getSourcePath($path));
+ }
+
+ /**
+ * @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
@@ -442,4 +450,40 @@ class Jail extends Wrapper {
public function changeLock($path, $type, ILockingProvider $provider) {
$this->storage->changeLock($this->getSourcePath($path), $type, $provider);
}
+
+ /**
+ * Resolve the path for the source of the share
+ *
+ * @param string $path
+ * @return array
+ */
+ public function resolvePath($path) {
+ return [$this->storage, $this->getSourcePath($path)];
+ }
+
+ /**
+ * @param \OCP\Files\Storage $sourceStorage
+ * @param string $sourceInternalPath
+ * @param string $targetInternalPath
+ * @return bool
+ */
+ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+ if ($sourceStorage === $this) {
+ return $this->copy($sourceInternalPath, $targetInternalPath);
+ }
+ return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath));
+ }
+
+ /**
+ * @param \OCP\Files\Storage $sourceStorage
+ * @param string $sourceInternalPath
+ * @param string $targetInternalPath
+ * @return bool
+ */
+ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+ if ($sourceStorage === $this) {
+ return $this->rename($sourceInternalPath, $targetInternalPath);
+ }
+ return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath));
+ }
}
diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php
index 12914e7a1b8..21d7db1099b 100644
--- a/lib/private/files/storage/wrapper/wrapper.php
+++ b/lib/private/files/storage/wrapper/wrapper.php
@@ -35,6 +35,12 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage {
*/
protected $storage;
+ public $cache;
+ public $scanner;
+ public $watcher;
+ public $propagator;
+ public $updater;
+
/**
* @param array $parameters
*/
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 70c50bb7b4b..e6aaed0fd15 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -628,7 +628,7 @@ class OC_Helper {
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
$quota = $sourceStorage->getQuota();
}
- $free = $storage->free_space('');
+ $free = $sourceStorage->free_space('');
if ($free >= 0) {
$total = $free + $used;
} else {
diff --git a/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php
index 9ce1396c1d1..bc7bf81709f 100644
--- a/lib/public/files/mount/imountpoint.php
+++ b/lib/public/files/mount/imountpoint.php
@@ -94,4 +94,12 @@ interface IMountPoint {
* @since 8.1.0
*/
public function getOptions();
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ * @since 9.1.0
+ */
+ public function getStorageRootId();
}
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 197fa874388..7d79150449c 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -647,7 +647,7 @@ class ManagerTest extends \Test\TestCase {
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
- $nonMoveableMountPermssions = $this->getMock('\OCP\Files\File');
+ $nonMoveableMountPermssions = $this->getMock('\OCP\Files\Folder');
$nonMoveableMountPermssions->method('isShareable')->willReturn(true);
$nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
@@ -2477,7 +2477,9 @@ class ManagerTest extends \Test\TestCase {
public function testMoveShareUser() {
$share = $this->manager->newShare();
- $share->setShareType(\OCP\Share::SHARE_TYPE_USER);
+ $share->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setId('42')
+ ->setProviderId('foo');
$share->setSharedWith('recipient');
@@ -2508,7 +2510,9 @@ class ManagerTest extends \Test\TestCase {
public function testMoveShareGroup() {
$share = $this->manager->newShare();
- $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
+ $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+ ->setId('42')
+ ->setProviderId('foo');
$group = $this->getMock('\OCP\IGroup');
$share->setSharedWith('group');