Skip to content

Commit dff96f9

Browse files
authored
Merge pull request #57542 from nextcloud/backport/51145/stable32
[stable32] feat: Add appconfig to disable fixed userfolder permissions optimization
2 parents 9a9978c + 2830121 commit dff96f9

27 files changed

+347
-143
lines changed

apps/files/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'OCA\\Files\\Command\\ScanAppData' => $baseDir . '/../lib/Command/ScanAppData.php',
5151
'OCA\\Files\\Command\\TransferOwnership' => $baseDir . '/../lib/Command/TransferOwnership.php',
5252
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => $baseDir . '/../lib/Command/WindowsCompatibleFilenames.php',
53+
'OCA\\Files\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
5354
'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php',
5455
'OCA\\Files\\Controller\\ConversionApiController' => $baseDir . '/../lib/Controller/ConversionApiController.php',
5556
'OCA\\Files\\Controller\\DirectEditingController' => $baseDir . '/../lib/Controller/DirectEditingController.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ComposerStaticInitFiles
6565
'OCA\\Files\\Command\\ScanAppData' => __DIR__ . '/..' . '/../lib/Command/ScanAppData.php',
6666
'OCA\\Files\\Command\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Command/TransferOwnership.php',
6767
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => __DIR__ . '/..' . '/../lib/Command/WindowsCompatibleFilenames.php',
68+
'OCA\\Files\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
6869
'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php',
6970
'OCA\\Files\\Controller\\ConversionApiController' => __DIR__ . '/..' . '/../lib/Controller/ConversionApiController.php',
7071
'OCA\\Files\\Controller\\DirectEditingController' => __DIR__ . '/..' . '/../lib/Controller/DirectEditingController.php',

apps/files/lib/AppInfo/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Files\Capabilities;
1414
use OCA\Files\Collaboration\Resources\Listener;
1515
use OCA\Files\Collaboration\Resources\ResourceProvider;
16+
use OCA\Files\ConfigLexicon;
1617
use OCA\Files\Controller\ApiController;
1718
use OCA\Files\Dashboard\FavoriteWidget;
1819
use OCA\Files\DirectEditingCapabilities;
@@ -124,6 +125,9 @@ public function register(IRegistrationContext $context): void {
124125

125126
$context->registerNotifierService(Notifier::class);
126127
$context->registerDashboardWidget(FavoriteWidget::class);
128+
129+
$context->registerConfigLexicon(ConfigLexicon::class);
130+
127131
}
128132

129133
public function boot(IBootContext $context): void {

apps/files/lib/ConfigLexicon.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files;
10+
11+
use OCP\Config\Lexicon\Entry;
12+
use OCP\Config\Lexicon\ILexicon;
13+
use OCP\Config\Lexicon\Strictness;
14+
use OCP\Config\ValueType;
15+
16+
/**
17+
* Config Lexicon for files.
18+
*
19+
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
20+
*
21+
* {@see ILexicon}
22+
*/
23+
class ConfigLexicon implements ILexicon {
24+
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';
25+
26+
public function getStrictness(): Strictness {
27+
return Strictness::NOTICE;
28+
}
29+
30+
public function getAppConfigs(): array {
31+
return [
32+
new Entry(
33+
self::OVERWRITES_HOME_FOLDERS,
34+
ValueType::ARRAY,
35+
defaultRaw: [],
36+
definition: 'List of applications overwriting home folders',
37+
lazy: false,
38+
note: 'It will be populated with app IDs of mount providers that overwrite home folders. Currently, only files_external and groupfolders.',
39+
),
40+
];
41+
}
42+
43+
public function getUserConfigs(): array {
44+
return [];
45+
}
46+
}

apps/files_external/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This application enables administrators to configure connections to external sto
1414

1515
External storage can be configured using the GUI or at the command line. This second option provides the administration with more flexibility for configuring bulk external storage mounts and setting mount priorities. More information is available in the external storage GUI documentation and the external storage Configuration File documentation.
1616
</description>
17-
<version>1.24.0</version>
17+
<version>1.24.1</version>
1818
<licence>agpl</licence>
1919
<author>Robin Appelman</author>
2020
<author>Michael Gapczynski</author>

apps/files_external/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
'OCA\\Files_External\\Migration\\Version1011Date20200630192246' => $baseDir . '/../lib/Migration/Version1011Date20200630192246.php',
108108
'OCA\\Files_External\\Migration\\Version1015Date20211104103506' => $baseDir . '/../lib/Migration/Version1015Date20211104103506.php',
109109
'OCA\\Files_External\\Migration\\Version1016Date20220324154536' => $baseDir . '/../lib/Migration/Version1016Date20220324154536.php',
110+
'OCA\\Files_External\\Migration\\Version1025Date20250228162604' => $baseDir . '/../lib/Migration/Version1025Date20250228162604.php',
110111
'OCA\\Files_External\\Migration\\Version22000Date20210216084416' => $baseDir . '/../lib/Migration/Version22000Date20210216084416.php',
111112
'OCA\\Files_External\\MountConfig' => $baseDir . '/../lib/MountConfig.php',
112113
'OCA\\Files_External\\NotFoundException' => $baseDir . '/../lib/NotFoundException.php',

apps/files_external/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ComposerStaticInitFiles_External
122122
'OCA\\Files_External\\Migration\\Version1011Date20200630192246' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20200630192246.php',
123123
'OCA\\Files_External\\Migration\\Version1015Date20211104103506' => __DIR__ . '/..' . '/../lib/Migration/Version1015Date20211104103506.php',
124124
'OCA\\Files_External\\Migration\\Version1016Date20220324154536' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date20220324154536.php',
125+
'OCA\\Files_External\\Migration\\Version1025Date20250228162604' => __DIR__ . '/..' . '/../lib/Migration/Version1025Date20250228162604.php',
125126
'OCA\\Files_External\\Migration\\Version22000Date20210216084416' => __DIR__ . '/..' . '/../lib/Migration/Version22000Date20210216084416.php',
126127
'OCA\\Files_External\\MountConfig' => __DIR__ . '/..' . '/../lib/MountConfig.php',
127128
'OCA\\Files_External\\NotFoundException' => __DIR__ . '/..' . '/../lib/NotFoundException.php',
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Files_External\Migration;
11+
12+
use Closure;
13+
use OCA\Files_External\Service\GlobalStoragesService;
14+
use OCP\DB\ISchemaWrapper;
15+
use OCP\IAppConfig;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
19+
/**
20+
* Check for any external storage overwriting the home folder
21+
*/
22+
class Version1025Date20250228162604 extends SimpleMigrationStep {
23+
public function __construct(
24+
private GlobalStoragesService $globalStoragesServices,
25+
private IAppConfig $appConfig,
26+
) {
27+
}
28+
29+
/**
30+
* @param Closure(): ISchemaWrapper $schemaClosure
31+
*/
32+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
33+
$this->globalStoragesServices->updateOverwriteHomeFolders();
34+
}
35+
}

apps/files_external/lib/Service/DBConfigService.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
8+
89
namespace OCA\Files_External\Service;
910

1011
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
@@ -64,16 +65,16 @@ public function getMountsForUser($userId, $groupIds) {
6465
->where($builder->expr()->orX(
6566
$builder->expr()->andX( // global mounts
6667
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
67-
$builder->expr()->isNull('a.value')
68+
$builder->expr()->isNull('a.value'),
6869
),
6970
$builder->expr()->andX( // mounts for user
7071
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
71-
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
72+
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId)),
7273
),
7374
$builder->expr()->andX( // mounts for group
7475
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
75-
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
76-
)
76+
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)),
77+
),
7778
));
7879

7980
return $this->getMountsFromQuery($query);
@@ -94,8 +95,8 @@ protected function modifyMountsOnDelete(string $applicableId, int $applicableTyp
9495
->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
9596
->where($builder->expr()->andX(
9697
$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
97-
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
98-
)
98+
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId)),
99+
),
99100
)
100101
->groupBy(['a.mount_id']);
101102
$stmt = $query->executeQuery();
@@ -227,7 +228,7 @@ public function addMount($mountPoint, $storageBackend, $authBackend, $priority,
227228
'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
228229
'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
229230
'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
230-
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
231+
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT),
231232
]);
232233
$query->executeStatement();
233234
return $query->getLastInsertId();
@@ -498,4 +499,17 @@ private function decryptValue($value) {
498499
return $value;
499500
}
500501
}
502+
503+
/**
504+
* Check if any mountpoint is configured that overwrite the home folder
505+
*/
506+
public function hasHomeFolderOverwriteMount(): bool {
507+
$builder = $this->connection->getQueryBuilder();
508+
$query = $builder->select('mount_id')
509+
->from('external_mounts')
510+
->where($builder->expr()->eq('mount_point', $builder->createNamedParameter('/')))
511+
->setMaxResults(1);
512+
$result = $query->executeQuery();
513+
return count($result->fetchAll()) > 0;
514+
}
501515
}

apps/files_external/lib/Service/StoragesService.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use OC\Files\Cache\Storage;
1111
use OC\Files\Filesystem;
12+
use OCA\Files\AppInfo\Application as FilesApplication;
13+
use OCA\Files\ConfigLexicon;
14+
use OCA\Files_External\AppInfo\Application;
1215
use OCA\Files_External\Lib\Auth\AuthMechanism;
1316
use OCA\Files_External\Lib\Auth\InvalidAuth;
1417
use OCA\Files_External\Lib\Backend\Backend;
@@ -20,6 +23,7 @@
2023
use OCP\Files\Config\IUserMountCache;
2124
use OCP\Files\Events\InvalidateMountCacheEvent;
2225
use OCP\Files\StorageNotAvailableException;
26+
use OCP\IAppConfig;
2327
use OCP\Server;
2428
use OCP\Util;
2529
use Psr\Log\LoggerInterface;
@@ -40,6 +44,7 @@ public function __construct(
4044
protected DBConfigService $dbConfig,
4145
protected IUserMountCache $userMountCache,
4246
protected IEventDispatcher $eventDispatcher,
47+
protected IAppConfig $appConfig,
4348
) {
4449
}
4550

@@ -242,6 +247,9 @@ public function addStorage(StorageConfig $newStorage) {
242247
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
243248

244249
$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
250+
251+
$this->updateOverwriteHomeFolders();
252+
245253
return $newStorage;
246254
}
247255

@@ -425,6 +433,8 @@ public function updateStorage(StorageConfig $updatedStorage) {
425433
}
426434
}
427435

436+
$this->updateOverwriteHomeFolders();
437+
428438
return $this->getStorage($id);
429439
}
430440

@@ -449,6 +459,8 @@ public function removeStorage(int $id) {
449459

450460
// delete oc_storages entries and oc_filecache
451461
Storage::cleanByMountId($id);
462+
463+
$this->updateOverwriteHomeFolders();
452464
}
453465

454466
/**
@@ -473,4 +485,20 @@ private function getStorageId(StorageConfig $storageConfig) {
473485
return -1;
474486
}
475487
}
488+
489+
public function updateOverwriteHomeFolders(): void {
490+
$appIdsList = $this->appConfig->getValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS);
491+
492+
if ($this->dbConfig->hasHomeFolderOverwriteMount()) {
493+
if (!in_array(Application::APP_ID, $appIdsList)) {
494+
$appIdsList[] = Application::APP_ID;
495+
$this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList);
496+
}
497+
} else {
498+
if (in_array(Application::APP_ID, $appIdsList)) {
499+
$appIdsList = array_values(array_filter($appIdsList, fn ($v) => $v !== Application::APP_ID));
500+
$this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList);
501+
}
502+
}
503+
}
476504
}

0 commit comments

Comments
 (0)