diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index d5257d79304e6..42dd0f0519da5 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -12,12 +12,14 @@ use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; use OC\User\LazyUser; +use OCA\Files_Sharing\AppInfo\Application; use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Defaults; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IL10N; @@ -56,6 +58,7 @@ public function __construct( private ITimeFactory $timeFactory, private LoggerInterface $logger, private IManager $shareManager, + private IConfig $config, ) { } @@ -480,6 +483,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([ @@ -491,7 +503,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 cfc96a7041794..0998e58e27085 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -718,12 +718,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/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index e1a2c9a537538..0764331504a99 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -21,6 +21,7 @@ use OCP\Federation\ICloudFederationFactory; use OCP\Files\IRootFolder; use OCP\Http\Client\IClientService; +use OCP\IConfig; use OCP\IServerContainer; use OCP\L10N\IFactory; use OCP\Mail\IMailer; @@ -89,6 +90,7 @@ protected function defaultShareProvider() { $this->serverContainer->query(ITimeFactory::class), $this->serverContainer->get(LoggerInterface::class), $this->serverContainer->get(IManager::class), + $this->serverContainer->get(IConfig::class), ); } @@ -204,8 +206,8 @@ protected function getShareByCircleProvider() { return null; } - if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || - !class_exists('\OCA\Circles\ShareByCircleProvider') + if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') + || !class_exists('\OCA\Circles\ShareByCircleProvider') ) { $this->circlesAreNotAvailable = true; return null; @@ -309,9 +311,9 @@ public function getProvider($id) { public function getProviderForType($shareType) { $provider = null; - if ($shareType === IShare::TYPE_USER || - $shareType === IShare::TYPE_GROUP || - $shareType === IShare::TYPE_LINK + if ($shareType === IShare::TYPE_USER + || $shareType === IShare::TYPE_GROUP + || $shareType === IShare::TYPE_LINK ) { $provider = $this->defaultShareProvider(); } elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) { diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 42e1dcfbf0aa7..687aa13eb9207 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -16,6 +16,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; @@ -73,6 +74,8 @@ class DefaultShareProviderTest extends \Test\TestCase { /** @var LoggerInterface|MockObject */ protected $logger; + protected IConfig&MockObject $config; + protected IShareManager&MockObject $shareManager; protected function setUp(): void { @@ -88,6 +91,7 @@ protected function setUp(): void { $this->timeFactory = $this->createMock(ITimeFactory::class); $this->logger = $this->createMock(LoggerInterface::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')); @@ -107,6 +111,7 @@ protected function setUp(): void { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ); } @@ -471,6 +476,7 @@ public function testDeleteSingleShare() { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ]) ->setMethods(['getShareById']) ->getMock(); @@ -568,6 +574,7 @@ public function testDeleteGroupShareWithUserGroupShares() { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ]) ->setMethods(['getShareById']) ->getMock(); @@ -2572,6 +2579,7 @@ public function testGetSharesInFolder() { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ); $password = md5(time()); @@ -2672,6 +2680,7 @@ public function testGetAccessListNoCurrentAccessRequired() { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ); $u1 = $userManager->createUser('testShare1', 'test'); @@ -2775,6 +2784,7 @@ public function testGetAccessListCurrentAccessRequired() { $this->timeFactory, $this->logger, $this->shareManager, + $this->config, ); $u1 = $userManager->createUser('testShare1', 'test');