Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +58,7 @@ public function __construct(
private ITimeFactory $timeFactory,
private LoggerInterface $logger,
private IManager $shareManager,
private IConfig $config,
) {
}

Expand Down Expand Up @@ -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([
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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'));
Expand All @@ -107,6 +111,7 @@ protected function setUp(): void {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
);
}

Expand Down Expand Up @@ -471,6 +476,7 @@ public function testDeleteSingleShare() {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -568,6 +574,7 @@ public function testDeleteGroupShareWithUserGroupShares() {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -2572,6 +2579,7 @@ public function testGetSharesInFolder() {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
);

$password = md5(time());
Expand Down Expand Up @@ -2672,6 +2680,7 @@ public function testGetAccessListNoCurrentAccessRequired() {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down Expand Up @@ -2775,6 +2784,7 @@ public function testGetAccessListCurrentAccessRequired() {
$this->timeFactory,
$this->logger,
$this->shareManager,
$this->config,
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down
Loading