Skip to content

Commit 89d659c

Browse files
Merge pull request #51602 from nextcloud/fix/fix-default-share-folder-for-group-shares
2 parents 8bc5edf + 7070ba4 commit 89d659c

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

lib/private/Share20/DefaultShareProvider.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
use OC\Share20\Exception\InvalidShare;
1414
use OC\Share20\Exception\ProviderException;
1515
use OC\User\LazyUser;
16+
use OCA\Files_Sharing\AppInfo\Application;
1617
use OCP\AppFramework\Utility\ITimeFactory;
1718
use OCP\DB\QueryBuilder\IQueryBuilder;
1819
use OCP\Defaults;
1920
use OCP\Files\Folder;
2021
use OCP\Files\IRootFolder;
2122
use OCP\Files\Node;
23+
use OCP\IConfig;
2224
use OCP\IDBConnection;
2325
use OCP\IGroupManager;
2426
use OCP\IL10N;
@@ -58,6 +60,7 @@ public function __construct(
5860
private ITimeFactory $timeFactory,
5961
private LoggerInterface $logger,
6062
private IManager $shareManager,
63+
private IConfig $config,
6164
) {
6265
}
6366

@@ -485,6 +488,15 @@ public function deleteFromSelf(IShare $share, $recipient) {
485488
protected function createUserSpecificGroupShare(IShare $share, string $recipient): int {
486489
$type = $share->getNodeType();
487490

491+
$shareFolder = $this->config->getSystemValue('share_folder', '/');
492+
$allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
493+
if ($allowCustomShareFolder) {
494+
$shareFolder = $this->config->getUserValue($recipient, Application::APP_ID, 'share_folder', $shareFolder);
495+
}
496+
497+
$target = $shareFolder . '/' . $share->getNode()->getName();
498+
$target = \OC\Files\Filesystem::normalizePath($target);
499+
488500
$qb = $this->dbConn->getQueryBuilder();
489501
$qb->insert('share')
490502
->values([
@@ -496,7 +508,7 @@ protected function createUserSpecificGroupShare(IShare $share, string $recipient
496508
'item_type' => $qb->createNamedParameter($type),
497509
'item_source' => $qb->createNamedParameter($share->getNodeId()),
498510
'file_source' => $qb->createNamedParameter($share->getNodeId()),
499-
'file_target' => $qb->createNamedParameter($share->getTarget()),
511+
'file_target' => $qb->createNamedParameter($target),
500512
'permissions' => $qb->createNamedParameter($share->getPermissions()),
501513
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
502514
])->executeStatement();

lib/private/Share20/Manager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,12 @@ public function createShare(IShare $share) {
705705
}
706706

707707
// Generate the target
708-
$defaultShareFolder = $this->config->getSystemValue('share_folder', '/');
709-
$allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
710-
if ($allowCustomShareFolder) {
711-
$shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $defaultShareFolder);
712-
} else {
713-
$shareFolder = $defaultShareFolder;
708+
$shareFolder = $this->config->getSystemValue('share_folder', '/');
709+
if ($share->getShareType() === IShare::TYPE_USER) {
710+
$allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
711+
if ($allowCustomShareFolder) {
712+
$shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $shareFolder);
713+
}
714714
}
715715

716716
$target = $shareFolder . '/' . $share->getNode()->getName();

tests/lib/Share20/DefaultShareProviderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCP\Files\File;
2121
use OCP\Files\Folder;
2222
use OCP\Files\IRootFolder;
23+
use OCP\IConfig;
2324
use OCP\IDBConnection;
2425
use OCP\IGroup;
2526
use OCP\IGroupManager;
@@ -79,6 +80,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
7980
/** @var LoggerInterface|MockObject */
8081
protected $logger;
8182

83+
protected IConfig&MockObject $config;
84+
8285
protected IShareManager&MockObject $shareManager;
8386

8487
protected function setUp(): void {
@@ -94,6 +97,7 @@ protected function setUp(): void {
9497
$this->timeFactory = $this->createMock(ITimeFactory::class);
9598
$this->logger = $this->createMock(LoggerInterface::class);
9699
$this->shareManager = $this->createMock(IShareManager::class);
100+
$this->config = $this->createMock(IConfig::class);
97101

98102
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
99103
$this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable('2023-05-04 00:00 Europe/Berlin'));
@@ -113,6 +117,7 @@ protected function setUp(): void {
113117
$this->timeFactory,
114118
$this->logger,
115119
$this->shareManager,
120+
$this->config,
116121
);
117122
}
118123

@@ -477,6 +482,7 @@ public function testDeleteSingleShare(): void {
477482
$this->timeFactory,
478483
$this->logger,
479484
$this->shareManager,
485+
$this->config,
480486
])
481487
->onlyMethods(['getShareById'])
482488
->getMock();
@@ -574,6 +580,7 @@ public function testDeleteGroupShareWithUserGroupShares(): void {
574580
$this->timeFactory,
575581
$this->logger,
576582
$this->shareManager,
583+
$this->config,
577584
])
578585
->onlyMethods(['getShareById'])
579586
->getMock();
@@ -2566,6 +2573,7 @@ public function testGetSharesInFolder(): void {
25662573
$this->timeFactory,
25672574
$this->logger,
25682575
$this->shareManager,
2576+
$this->config,
25692577
);
25702578

25712579
$password = md5(time());
@@ -2666,6 +2674,7 @@ public function testGetAccessListNoCurrentAccessRequired(): void {
26662674
$this->timeFactory,
26672675
$this->logger,
26682676
$this->shareManager,
2677+
$this->config,
26692678
);
26702679

26712680
$u1 = $userManager->createUser('testShare1', 'test');
@@ -2769,6 +2778,7 @@ public function testGetAccessListCurrentAccessRequired(): void {
27692778
$this->timeFactory,
27702779
$this->logger,
27712780
$this->shareManager,
2781+
$this->config,
27722782
);
27732783

27742784
$u1 = $userManager->createUser('testShare1', 'test');

0 commit comments

Comments
 (0)