diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 8c651dd889ca2..45a5aba21696c 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -44,6 +44,7 @@ use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -105,6 +106,7 @@ public function __construct( IURLGenerator $urlGenerator, ITimeFactory $timeFactory, private IManager $shareManager, + private IConfig $config, ) { $this->dbConn = $connection; $this->userManager = $userManager; @@ -547,6 +549,15 @@ public function deleteFromSelf(IShare $share, $recipient) { protected function createUserSpecificGroupShare(IShare $share, string $recipient): int { $type = $share->getNodeType(); + $shareFolder = $this->config->getSystemValue('share_folder', '/'); + $allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true); + if ($allowCustomShareFolder) { + $shareFolder = $this->config->getUserValue($recipient, Application::APP_ID, 'share_folder', $shareFolder); + } + + $target = $shareFolder . '/' . $share->getNode()->getName(); + $target = \OC\Files\Filesystem::normalizePath($target); + $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share') ->values([ @@ -558,7 +569,7 @@ protected function createUserSpecificGroupShare(IShare $share, string $recipient 'item_type' => $qb->createNamedParameter($type), 'item_source' => $qb->createNamedParameter($share->getNodeId()), 'file_source' => $qb->createNamedParameter($share->getNodeId()), - 'file_target' => $qb->createNamedParameter($share->getTarget()), + 'file_target' => $qb->createNamedParameter($target), 'permissions' => $qb->createNamedParameter($share->getPermissions()), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), ])->execute(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index c7a42bbbf02e9..5d79e2e033e00 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -750,12 +750,12 @@ public function createShare(IShare $share) { } // Generate the target - $defaultShareFolder = $this->config->getSystemValue('share_folder', '/'); - $allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true); - if ($allowCustomShareFolder) { - $shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $defaultShareFolder); - } else { - $shareFolder = $defaultShareFolder; + $shareFolder = $this->config->getSystemValue('share_folder', '/'); + if ($share->getShareType() === IShare::TYPE_USER) { + $allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true); + if ($allowCustomShareFolder) { + $shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $shareFolder); + } } $target = $shareFolder . '/' . $share->getNode()->getName(); diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 3c816bcb02539..063cfeb517cfd 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -30,6 +30,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; use OCP\IGroupManager; @@ -98,6 +99,7 @@ protected function setUp(): void { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->shareManager = $this->createMock(IShareManager::class); + $this->config = $this->createMock(IConfig::class); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); $this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable("2023-05-04 00:00 Europe/Berlin")); @@ -116,6 +118,7 @@ protected function setUp(): void { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ); } @@ -478,6 +481,7 @@ public function testDeleteSingleShare() { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ]) ->setMethods(['getShareById']) ->getMock(); @@ -574,6 +578,7 @@ public function testDeleteGroupShareWithUserGroupShares() { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ]) ->setMethods(['getShareById']) ->getMock(); @@ -2569,6 +2574,7 @@ public function testGetSharesInFolder() { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ); $password = md5(time()); @@ -2668,6 +2674,7 @@ public function testGetAccessListNoCurrentAccessRequired() { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ); $u1 = $userManager->createUser('testShare1', 'test'); @@ -2770,6 +2777,7 @@ public function testGetAccessListCurrentAccessRequired() { $this->urlGenerator, $this->timeFactory, $this->shareManager, + $this->config, ); $u1 = $userManager->createUser('testShare1', 'test');