Skip to content

Commit 12ceeac

Browse files
committed
fix: Use default share folder of the user on share accept
Signed-off-by: Côme Chilliet <[email protected]>
1 parent f05ae48 commit 12ceeac

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-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
@@ -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();

0 commit comments

Comments
 (0)