diff --git a/apps/files_sharing/tests/EtagPropagationTest.php b/apps/files_sharing/tests/EtagPropagationTest.php index fb6fcce61966..b199ff0ee0e3 100644 --- a/apps/files_sharing/tests/EtagPropagationTest.php +++ b/apps/files_sharing/tests/EtagPropagationTest.php @@ -179,6 +179,7 @@ protected function setUpShares() { $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag(); } } + $this->logout(); } public function testOwnerWritesToShare() { @@ -442,6 +443,7 @@ public function testRecipientUploadInDirectReshare() { } 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'); diff --git a/apps/files_sharing/tests/SharedMountTest.php b/apps/files_sharing/tests/SharedMountTest.php index 3af41e36dbd6..6ff9856cc494 100644 --- a/apps/files_sharing/tests/SharedMountTest.php +++ b/apps/files_sharing/tests/SharedMountTest.php @@ -303,6 +303,7 @@ public function testPermissionMovedGroupShare($type, $beforePerm, $afterPerm) { \OC\Files\Filesystem::rename($path, "newPath"); $this->assertTrue(\OC\Files\Filesystem::file_exists('newPath')); $this->assertFalse(\OC\Files\Filesystem::file_exists($path)); + $this->logout(); // change permissions $share->setPermissions($afterPerm); diff --git a/lib/private/Server.php b/lib/private/Server.php index b0af15835d4d..f85d60e07c1b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -886,7 +886,8 @@ public function __construct($webRoot, \OC\Config $config) { $c->getLazyRootFolder(), $c->getEventDispatcher(), new View('/'), - $c->getDatabaseConnection() + $c->getDatabaseConnection(), + $c->getUserSession() ); return $manager; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ea5a1cc326ac..d1c4f476db80 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -40,6 +40,7 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IUserManager; +use OCP\IUserSession; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\Exceptions\GenericShareException; @@ -85,6 +86,8 @@ class Manager implements IManager { private $view; /** @var IDBConnection */ private $connection; + /** @var IUserSession */ + private $userSession; /** * Manager constructor. @@ -99,6 +102,10 @@ class Manager implements IManager { * @param IProviderFactory $factory * @param IUserManager $userManager * @param IRootFolder $rootFolder + * @param EventDispatcher $eventDispatcher + * @param View $view + * @param IDBConnection $connection + * @param IUserSession $userSession */ public function __construct( ILogger $logger, @@ -113,7 +120,8 @@ public function __construct( IRootFolder $rootFolder, EventDispatcher $eventDispatcher, View $view, - IDBConnection $connection + IDBConnection $connection, + IUserSession $userSession = null ) { $this->logger = $logger; $this->config = $config; @@ -129,6 +137,7 @@ public function __construct( $this->eventDispatcher = $eventDispatcher; $this->view = $view; $this->connection = $connection; + $this->userSession = $userSession; } /** @@ -322,7 +331,8 @@ protected function validatePermissions(IShare $share) { } /** If it is re-share, calculate $maxPermissions based on all incoming share permissions */ - if ($shareNode->getOwner()->getUID() !== $share->getSharedBy()) { + if ($this->userSession !== null && $this->userSession->getUser() !== null && + $share->getShareOwner() !== $this->userSession->getUser()->getUID()) { $maxPermissions = $this->calculateReshareNodePermissions($share); } @@ -642,8 +652,6 @@ protected function canShare(\OCP\Share\IShare $share) { public function createShare(\OCP\Share\IShare $share) { $this->canShare($share); - $this->generalChecks($share); - // Verify if there are any issues with the path $this->pathCreateChecks($share->getNode()); @@ -662,6 +670,8 @@ public function createShare(\OCP\Share\IShare $share) { $share->setShareOwner($share->getNode()->getOwner()->getUID()); } + $this->generalChecks($share); + //Verify share type if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { $this->userCreateChecks($share); @@ -1280,13 +1290,13 @@ public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $o */ public function getAllSharedWith($userId, $shareTypes, $node = null) { $shares = []; - + // Aggregate all required $shareTypes by mapping provider to supported shareTypes $providerIdMap = $this->shareTypeToProviderMap($shareTypes); foreach ($providerIdMap as $providerId => $shareTypeArray) { // Get provider from cache $provider = $this->factory->getProvider($providerId); - + // Obtain all shares for all the supported provider types $queriedShares = $provider->getAllSharedWith($userId, $node); $shares = \array_merge($shares, $queriedShares); @@ -1294,7 +1304,7 @@ public function getAllSharedWith($userId, $shareTypes, $node = null) { return $shares; } - + /** * @inheritdoc */