Skip to content

Commit b80b473

Browse files
committed
feat: mark homefolder as overwritten when an external storage mounted at / exists
Signed-off-by: Robin Appelman <[email protected]>
1 parent c2d710c commit b80b473

File tree

12 files changed

+86
-13
lines changed

12 files changed

+86
-13
lines changed

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.25.0</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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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\DBConfigService;
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 DBConfigService $dbConfig,
25+
private IAppConfig $appConfig,
26+
) {
27+
}
28+
29+
30+
/**
31+
* @param IOutput $output
32+
* @param Closure(): ISchemaWrapper $schemaClosure
33+
* @param array $options
34+
*/
35+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
36+
if ($this->dbConfig->hasHomeFolderOverwriteMount()) {
37+
$this->appConfig->setValueBool('files', 'homeFolderOverwritten', true);
38+
}
39+
}
40+
}

apps/files_external/lib/Service/DBConfigService.php

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

910
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
@@ -63,16 +64,16 @@ public function getMountsForUser($userId, $groupIds) {
6364
->where($builder->expr()->orX(
6465
$builder->expr()->andX( // global mounts
6566
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
66-
$builder->expr()->isNull('a.value')
67+
$builder->expr()->isNull('a.value'),
6768
),
6869
$builder->expr()->andX( // mounts for user
6970
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
70-
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
71+
$builder->expr()->eq('a.value', $builder->createNamedParameter($userId)),
7172
),
7273
$builder->expr()->andX( // mounts for group
7374
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
74-
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
75-
)
75+
$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)),
76+
),
7677
));
7778

7879
return $this->getMountsFromQuery($query);
@@ -93,8 +94,8 @@ protected function modifyMountsOnDelete(string $applicableId, int $applicableTyp
9394
->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
9495
->where($builder->expr()->andX(
9596
$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
96-
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
97-
)
97+
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId)),
98+
),
9899
)
99100
->groupBy(['a.mount_id']);
100101
$stmt = $query->executeQuery();
@@ -226,7 +227,7 @@ public function addMount($mountPoint, $storageBackend, $authBackend, $priority,
226227
'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
227228
'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
228229
'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
229-
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
230+
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT),
230231
]);
231232
$query->executeStatement();
232233
return $query->getLastInsertId();
@@ -497,4 +498,17 @@ private function decryptValue($value) {
497498
return $value;
498499
}
499500
}
501+
502+
/**
503+
* Check if any mountpoint is configured that overwrite the home folder
504+
*/
505+
public function hasHomeFolderOverwriteMount(): bool {
506+
$builder = $this->connection->getQueryBuilder();
507+
$query = $builder->select('mount_id')
508+
->from('external_mounts')
509+
->where($builder->expr()->eq('mount_point', $builder->createNamedParameter('/')))
510+
->setMaxResults(1);
511+
$result = $query->executeQuery();
512+
return (bool)$result->fetchColumn();
513+
}
500514
}

apps/files_external/lib/Service/StoragesService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\Files\Config\IUserMountCache;
2020
use OCP\Files\Events\InvalidateMountCacheEvent;
2121
use OCP\Files\StorageNotAvailableException;
22+
use OCP\IAppConfig;
2223
use OCP\Server;
2324
use OCP\Util;
2425
use Psr\Log\LoggerInterface;
@@ -39,6 +40,7 @@ public function __construct(
3940
protected DBConfigService $dbConfig,
4041
protected IUserMountCache $userMountCache,
4142
protected IEventDispatcher $eventDispatcher,
43+
protected IAppConfig $appConfig,
4244
) {
4345
}
4446

@@ -424,6 +426,10 @@ public function updateStorage(StorageConfig $updatedStorage) {
424426
}
425427
}
426428

429+
if ($this->dbConfig->hasHomeFolderOverwriteMount()) {
430+
$this->appConfig->setValueBool('files', 'homeFolderOverwritten', true);
431+
}
432+
427433
return $this->getStorage($id);
428434
}
429435

apps/files_external/lib/Service/UserGlobalStoragesService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use OCA\Files_External\Lib\StorageConfig;
1010
use OCP\EventDispatcher\IEventDispatcher;
1111
use OCP\Files\Config\IUserMountCache;
12+
use OCP\IAppConfig;
1213
use OCP\IGroupManager;
1314
use OCP\IUser;
1415
use OCP\IUserSession;
@@ -35,8 +36,9 @@ public function __construct(
3536
protected IGroupManager $groupManager,
3637
IUserMountCache $userMountCache,
3738
IEventDispatcher $eventDispatcher,
39+
IAppConfig $appConfig,
3840
) {
39-
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
41+
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig);
4042
$this->userSession = $userSession;
4143
}
4244

apps/files_external/lib/Service/UserStoragesService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Files_External\NotFoundException;
1313
use OCP\EventDispatcher\IEventDispatcher;
1414
use OCP\Files\Config\IUserMountCache;
15+
use OCP\IAppConfig;
1516
use OCP\IUserSession;
1617

1718
/**
@@ -36,9 +37,10 @@ public function __construct(
3637
IUserSession $userSession,
3738
IUserMountCache $userMountCache,
3839
IEventDispatcher $eventDispatcher,
40+
IAppConfig $appConfig,
3941
) {
4042
$this->userSession = $userSession;
41-
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
43+
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig);
4244
}
4345

4446
protected function readDBConfig() {

apps/files_external/tests/Service/GlobalStoragesServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class GlobalStoragesServiceTest extends StoragesServiceTest {
1818
protected function setUp(): void {
1919
parent::setUp();
20-
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
20+
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher, $this->appConfig);
2121
}
2222

2323
protected function tearDown(): void {

apps/files_external/tests/Service/StoragesServiceTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCP\Files\Config\IUserMountCache;
2626
use OCP\Files\Mount\IMountPoint;
2727
use OCP\Files\Storage\IStorage;
28+
use OCP\IAppConfig;
2829
use OCP\IConfig;
2930
use OCP\IDBConnection;
3031
use OCP\IUser;
@@ -86,6 +87,10 @@ abstract class StoragesServiceTest extends \Test\TestCase {
8687
* @var \PHPUnit\Framework\MockObject\MockObject|IEventDispatcher
8788
*/
8889
protected IEventDispatcher $eventDispatcher;
90+
/**
91+
* @var \PHPUnit\Framework\MockObject\MockObject|IAppConfig
92+
*/
93+
protected IAppConfig $appConfig;
8994

9095
protected function setUp(): void {
9196
parent::setUp();
@@ -100,6 +105,7 @@ protected function setUp(): void {
100105

101106
$this->mountCache = $this->createMock(IUserMountCache::class);
102107
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
108+
$this->appConfig = $this->createMock(IAppConfig::class);
103109

104110
// prepare BackendService mock
105111
$this->backendService =

0 commit comments

Comments
 (0)