|
65 | 65 | use OCP\Files\Mount\IMountPoint; |
66 | 66 | use OCP\Files\NotFoundException; |
67 | 67 | use OCP\Files\ReservedWordException; |
68 | | -use OCP\Files\Storage\IStorage; |
69 | 68 | use OCP\IUser; |
70 | 69 | use OCP\Lock\ILockingProvider; |
71 | 70 | use OCP\Lock\LockedException; |
| 71 | +use OCP\Server; |
| 72 | +use OCP\Share\IManager; |
| 73 | +use OCP\Share\IShare; |
72 | 74 | use Psr\Log\LoggerInterface; |
73 | 75 |
|
74 | 76 | /** |
@@ -731,6 +733,8 @@ public function deleteAll($directory) { |
731 | 733 | public function rename($source, $target) { |
732 | 734 | $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source)); |
733 | 735 | $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target)); |
| 736 | + $targetParts = explode('/', $absolutePath2); |
| 737 | + $targetUser = $targetParts[1] ?? null; |
734 | 738 | $result = false; |
735 | 739 | if ( |
736 | 740 | Filesystem::isValidPath($target) |
@@ -785,7 +789,7 @@ public function rename($source, $target) { |
785 | 789 | if ($internalPath1 === '') { |
786 | 790 | if ($mount1 instanceof MoveableMount) { |
787 | 791 | $sourceParentMount = $this->getMount(dirname($source)); |
788 | | - if ($sourceParentMount === $mount2 && $this->targetIsNotShared($storage2, $internalPath2)) { |
| 792 | + if ($sourceParentMount === $mount2 && $this->targetIsNotShared($targetUser, $absolutePath2)) { |
789 | 793 | /** |
790 | 794 | * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1 |
791 | 795 | */ |
@@ -1781,28 +1785,29 @@ private function assertPathLength($path): void { |
1781 | 1785 | * It is not allowed to move a mount point into a different mount point or |
1782 | 1786 | * into an already shared folder |
1783 | 1787 | */ |
1784 | | - private function targetIsNotShared(IStorage $targetStorage, string $targetInternalPath): bool { |
1785 | | - // note: cannot use the view because the target is already locked |
1786 | | - $fileId = $targetStorage->getCache()->getId($targetInternalPath); |
1787 | | - if ($fileId === -1) { |
1788 | | - // target might not exist, need to check parent instead |
1789 | | - $fileId = $targetStorage->getCache()->getId(dirname($targetInternalPath)); |
1790 | | - } |
1791 | | - |
1792 | | - // check if any of the parents were shared by the current owner (include collections) |
1793 | | - $shares = Share::getItemShared( |
1794 | | - 'folder', |
1795 | | - (string)$fileId, |
1796 | | - \OC\Share\Constants::FORMAT_NONE, |
1797 | | - null, |
1798 | | - true |
1799 | | - ); |
1800 | | - |
1801 | | - if (count($shares) > 0) { |
1802 | | - $this->logger->debug( |
1803 | | - 'It is not allowed to move one mount point into a shared folder', |
1804 | | - ['app' => 'files']); |
1805 | | - return false; |
| 1788 | + private function targetIsNotShared(string $user, string $targetPath): bool { |
| 1789 | + $providers = [ |
| 1790 | + IShare::TYPE_USER, |
| 1791 | + IShare::TYPE_GROUP, |
| 1792 | + IShare::TYPE_EMAIL, |
| 1793 | + IShare::TYPE_CIRCLE, |
| 1794 | + IShare::TYPE_ROOM, |
| 1795 | + IShare::TYPE_DECK, |
| 1796 | + IShare::TYPE_SCIENCEMESH |
| 1797 | + ]; |
| 1798 | + $shareManager = Server::get(IManager::class); |
| 1799 | + /** @var IShare[] $shares */ |
| 1800 | + $shares = array_merge(...array_map(function (int $type) use ($shareManager, $user) { |
| 1801 | + return $shareManager->getSharesBy($user, $type); |
| 1802 | + }, $providers)); |
| 1803 | + |
| 1804 | + foreach ($shares as $share) { |
| 1805 | + if (str_starts_with($targetPath, $share->getNode()->getPath())) { |
| 1806 | + $this->logger->debug( |
| 1807 | + 'It is not allowed to move one mount point into a shared folder', |
| 1808 | + ['app' => 'files']); |
| 1809 | + return false; |
| 1810 | + } |
1806 | 1811 | } |
1807 | 1812 |
|
1808 | 1813 | return true; |
|
0 commit comments