Skip to content

Commit 2792cd8

Browse files
authored
Merge pull request #54130 from nextcloud/backport/51602/stable31
2 parents ab718ee + 2da5f0b commit 2792cd8

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

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
@@ -704,12 +704,12 @@ public function createShare(IShare $share) {
704704
}
705705

706706
// Generate the target
707-
$defaultShareFolder = $this->config->getSystemValue('share_folder', '/');
708-
$allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
709-
if ($allowCustomShareFolder) {
710-
$shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $defaultShareFolder);
711-
} else {
712-
$shareFolder = $defaultShareFolder;
707+
$shareFolder = $this->config->getSystemValue('share_folder', '/');
708+
if ($share->getShareType() === IShare::TYPE_USER) {
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', $shareFolder);
712+
}
713713
}
714714

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

lib/private/Share20/ProviderFactory.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Federation\ICloudFederationFactory;
2222
use OCP\Files\IRootFolder;
2323
use OCP\Http\Client\IClientService;
24+
use OCP\IConfig;
2425
use OCP\IServerContainer;
2526
use OCP\L10N\IFactory;
2627
use OCP\Mail\IMailer;
@@ -88,6 +89,7 @@ protected function defaultShareProvider() {
8889
$this->serverContainer->get(ITimeFactory::class),
8990
$this->serverContainer->get(LoggerInterface::class),
9091
$this->serverContainer->get(IManager::class),
92+
$this->serverContainer->get(IConfig::class),
9193
);
9294
}
9395

@@ -203,8 +205,8 @@ protected function getShareByCircleProvider() {
203205
return null;
204206
}
205207

206-
if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') ||
207-
!class_exists('\OCA\Circles\ShareByCircleProvider')
208+
if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles')
209+
|| !class_exists('\OCA\Circles\ShareByCircleProvider')
208210
) {
209211
$this->circlesAreNotAvailable = true;
210212
return null;
@@ -308,9 +310,9 @@ public function getProvider($id) {
308310
public function getProviderForType($shareType) {
309311
$provider = null;
310312

311-
if ($shareType === IShare::TYPE_USER ||
312-
$shareType === IShare::TYPE_GROUP ||
313-
$shareType === IShare::TYPE_LINK
313+
if ($shareType === IShare::TYPE_USER
314+
|| $shareType === IShare::TYPE_GROUP
315+
|| $shareType === IShare::TYPE_LINK
314316
) {
315317
$provider = $this->defaultShareProvider();
316318
} elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) {

tests/lib/Share20/DefaultShareProviderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\Files\File;
1717
use OCP\Files\Folder;
1818
use OCP\Files\IRootFolder;
19+
use OCP\IConfig;
1920
use OCP\IDBConnection;
2021
use OCP\IGroup;
2122
use OCP\IGroupManager;
@@ -73,6 +74,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
7374
/** @var LoggerInterface|MockObject */
7475
protected $logger;
7576

77+
protected IConfig&MockObject $config;
78+
7679
protected IShareManager&MockObject $shareManager;
7780

7881
protected function setUp(): void {
@@ -88,6 +91,7 @@ protected function setUp(): void {
8891
$this->timeFactory = $this->createMock(ITimeFactory::class);
8992
$this->logger = $this->createMock(LoggerInterface::class);
9093
$this->shareManager = $this->createMock(IShareManager::class);
94+
$this->config = $this->createMock(IConfig::class);
9195

9296
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
9397
$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 {
107111
$this->timeFactory,
108112
$this->logger,
109113
$this->shareManager,
114+
$this->config,
110115
);
111116
}
112117

@@ -471,6 +476,7 @@ public function testDeleteSingleShare(): void {
471476
$this->timeFactory,
472477
$this->logger,
473478
$this->shareManager,
479+
$this->config,
474480
])
475481
->setMethods(['getShareById'])
476482
->getMock();
@@ -568,6 +574,7 @@ public function testDeleteGroupShareWithUserGroupShares(): void {
568574
$this->timeFactory,
569575
$this->logger,
570576
$this->shareManager,
577+
$this->config,
571578
])
572579
->setMethods(['getShareById'])
573580
->getMock();
@@ -2572,6 +2579,7 @@ public function testGetSharesInFolder(): void {
25722579
$this->timeFactory,
25732580
$this->logger,
25742581
$this->shareManager,
2582+
$this->config,
25752583
);
25762584

25772585
$password = md5(time());
@@ -2672,6 +2680,7 @@ public function testGetAccessListNoCurrentAccessRequired(): void {
26722680
$this->timeFactory,
26732681
$this->logger,
26742682
$this->shareManager,
2683+
$this->config,
26752684
);
26762685

26772686
$u1 = $userManager->createUser('testShare1', 'test');
@@ -2775,6 +2784,7 @@ public function testGetAccessListCurrentAccessRequired(): void {
27752784
$this->timeFactory,
27762785
$this->logger,
27772786
$this->shareManager,
2787+
$this->config,
27782788
);
27792789

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

0 commit comments

Comments
 (0)