-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
add appconfig to disable fixed userfolder permissions optimization #51145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Files_External\Migration; | ||
|
||
use Closure; | ||
use OCA\Files_External\Service\DBConfigService; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\IAppConfig; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
/** | ||
* Check for any external storage overwriting the home folder | ||
*/ | ||
class Version1025Date20250228162604 extends SimpleMigrationStep { | ||
public function __construct( | ||
private DBConfigService $dbConfig, | ||
private IAppConfig $appConfig, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
*/ | ||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
if ($this->dbConfig->hasHomeFolderOverwriteMount()) { | ||
$this->appConfig->setValueBool('files', 'homeFolderOverwritten', true); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. | ||||||||||
* SPDX-License-Identifier: AGPL-3.0-only | ||||||||||
*/ | ||||||||||
|
||||||||||
namespace OCA\Files_External\Service; | ||||||||||
|
||||||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException; | ||||||||||
|
@@ -63,16 +64,16 @@ | |||||||||
->where($builder->expr()->orX( | ||||||||||
$builder->expr()->andX( // global mounts | ||||||||||
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)), | ||||||||||
$builder->expr()->isNull('a.value') | ||||||||||
$builder->expr()->isNull('a.value'), | ||||||||||
), | ||||||||||
$builder->expr()->andX( // mounts for user | ||||||||||
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)), | ||||||||||
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId)) | ||||||||||
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId)), | ||||||||||
), | ||||||||||
$builder->expr()->andX( // mounts for group | ||||||||||
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)), | ||||||||||
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)) | ||||||||||
) | ||||||||||
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)), | ||||||||||
), | ||||||||||
)); | ||||||||||
|
||||||||||
return $this->getMountsFromQuery($query); | ||||||||||
|
@@ -93,8 +94,8 @@ | |||||||||
->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id')) | ||||||||||
->where($builder->expr()->andX( | ||||||||||
$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)), | ||||||||||
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId)) | ||||||||||
) | ||||||||||
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId)), | ||||||||||
), | ||||||||||
) | ||||||||||
->groupBy(['a.mount_id']); | ||||||||||
$stmt = $query->executeQuery(); | ||||||||||
|
@@ -226,7 +227,7 @@ | |||||||||
'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR), | ||||||||||
'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR), | ||||||||||
'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT), | ||||||||||
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) | ||||||||||
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT), | ||||||||||
]); | ||||||||||
$query->executeStatement(); | ||||||||||
return $query->getLastInsertId(); | ||||||||||
|
@@ -497,4 +498,19 @@ | |||||||||
return $value; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Check if any mountpoint is configured that overwrite the home folder | ||||||||||
* | ||||||||||
* @return bool | ||||||||||
Comment on lines
+504
to
+505
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
public function hasHomeFolderOverwriteMount(): bool { | ||||||||||
$builder = $this->connection->getQueryBuilder(); | ||||||||||
$query = $builder->select('mount_id') | ||||||||||
->from('external_mounts') | ||||||||||
->where($builder->expr()->eq('mount_point', $builder->createNamedParameter('/'))) | ||||||||||
->setMaxResults(1); | ||||||||||
$result = $query->executeQuery(); | ||||||||||
return (bool)$result->fetchColumn(); | ||||||||||
Check failure on line 514 in apps/files_external/lib/Service/DBConfigService.php
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or even
Suggested change
|
||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ | |||||||||
use OCP\Files\Config\IUserMountCache; | ||||||||||
use OCP\Files\Events\InvalidateMountCacheEvent; | ||||||||||
use OCP\Files\StorageNotAvailableException; | ||||||||||
use OCP\IAppConfig; | ||||||||||
use OCP\Server; | ||||||||||
use OCP\Util; | ||||||||||
use Psr\Log\LoggerInterface; | ||||||||||
|
@@ -39,6 +40,7 @@ public function __construct( | |||||||||
protected DBConfigService $dbConfig, | ||||||||||
protected IUserMountCache $userMountCache, | ||||||||||
protected IEventDispatcher $eventDispatcher, | ||||||||||
protected IAppConfig $appConfig, | ||||||||||
) { | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -424,6 +426,10 @@ public function updateStorage(StorageConfig $updatedStorage) { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if ($this->dbConfig->hasHomeFolderOverwriteMount()) { | ||||||||||
$this->appConfig->setValueBool('files', 'homeFolderOverwritten', true); | ||||||||||
} | ||||||||||
Comment on lines
+429
to
+431
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is it ever set to false?
Suggested change
|
||||||||||
|
||||||||||
return $this->getStorage($id); | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,6 +28,7 @@ | |||||||||||
use OCP\Files\Config\IUserMountCache; | ||||||||||||
use OCP\Files\Mount\IMountPoint; | ||||||||||||
use OCP\Files\Storage\IStorage; | ||||||||||||
use OCP\IAppConfig; | ||||||||||||
use OCP\IConfig; | ||||||||||||
use OCP\IDBConnection; | ||||||||||||
use OCP\IUser; | ||||||||||||
|
@@ -63,6 +64,10 @@ abstract class StoragesServiceTestCase extends \Test\TestCase { | |||||||||||
protected static array $hookCalls; | ||||||||||||
protected IUserMountCache&MockObject $mountCache; | ||||||||||||
protected IEventDispatcher&MockObject $eventDispatcher; | ||||||||||||
/** | ||||||||||||
* @var \PHPUnit\Framework\MockObject\MockObject|IAppConfig | ||||||||||||
*/ | ||||||||||||
protected IAppConfig $appConfig; | ||||||||||||
Comment on lines
+67
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
protected function setUp(): void { | ||||||||||||
parent::setUp(); | ||||||||||||
|
@@ -77,6 +82,7 @@ protected function setUp(): void { | |||||||||||
|
||||||||||||
$this->mountCache = $this->createMock(IUserMountCache::class); | ||||||||||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class); | ||||||||||||
$this->appConfig = $this->createMock(IAppConfig::class); | ||||||||||||
|
||||||||||||
// prepare BackendService mock | ||||||||||||
$this->backendService = $this->createMock(BackendService::class); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,20 @@ class LazyUserFolder extends LazyFolder { | |
private string $path; | ||
private IMountManager $mountManager; | ||
|
||
public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager) { | ||
public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager, bool $useDefaultPermissions = true) { | ||
$this->user = $user; | ||
$this->mountManager = $mountManager; | ||
$this->path = '/' . $user->getUID() . '/files'; | ||
$data = [ | ||
'path' => $this->path, | ||
// Sharing user root folder is not allowed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be before line 37, it comments the permission setting. |
||
'type' => FileInfo::TYPE_FOLDER, | ||
'mimetype' => FileInfo::MIMETYPE_FOLDER, | ||
]; | ||
if ($useDefaultPermissions) { | ||
$data['permissions'] = Constants::PERMISSION_ALL ^ Constants::PERMISSION_SHARE; | ||
} | ||
|
||
parent::__construct($rootFolder, function () use ($user): Folder { | ||
try { | ||
$node = $this->getRootFolder()->get($this->path); | ||
|
@@ -44,13 +54,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager | |
} | ||
return $this->getRootFolder()->newFolder($this->path); | ||
} | ||
}, [ | ||
'path' => $this->path, | ||
// Sharing user root folder is not allowed | ||
'permissions' => Constants::PERMISSION_ALL ^ Constants::PERMISSION_SHARE, | ||
'type' => FileInfo::TYPE_FOLDER, | ||
'mimetype' => FileInfo::MIMETYPE_FOLDER, | ||
]); | ||
}, $data); | ||
} | ||
|
||
public function getMountPoint() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.