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
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'OCA\\Files\\Command\\ScanAppData' => $baseDir . '/../lib/Command/ScanAppData.php',
'OCA\\Files\\Command\\TransferOwnership' => $baseDir . '/../lib/Command/TransferOwnership.php',
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => $baseDir . '/../lib/Command/WindowsCompatibleFilenames.php',
'OCA\\Files\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ConversionApiController' => $baseDir . '/../lib/Controller/ConversionApiController.php',
'OCA\\Files\\Controller\\DirectEditingController' => $baseDir . '/../lib/Controller/DirectEditingController.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Command\\ScanAppData' => __DIR__ . '/..' . '/../lib/Command/ScanAppData.php',
'OCA\\Files\\Command\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Command/TransferOwnership.php',
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => __DIR__ . '/..' . '/../lib/Command/WindowsCompatibleFilenames.php',
'OCA\\Files\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ConversionApiController' => __DIR__ . '/..' . '/../lib/Controller/ConversionApiController.php',
'OCA\\Files\\Controller\\DirectEditingController' => __DIR__ . '/..' . '/../lib/Controller/DirectEditingController.php',
Expand Down
4 changes: 4 additions & 0 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\ConfigLexicon;
use OCA\Files\Controller\ApiController;
use OCA\Files\Dashboard\FavoriteWidget;
use OCA\Files\DirectEditingCapabilities;
Expand Down Expand Up @@ -124,6 +125,9 @@ public function register(IRegistrationContext $context): void {

$context->registerNotifierService(Notifier::class);
$context->registerDashboardWidget(FavoriteWidget::class);

$context->registerConfigLexicon(ConfigLexicon::class);

}

public function boot(IBootContext $context): void {
Expand Down
46 changes: 46 additions & 0 deletions apps/files/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files;

use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for files.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';

public function getStrictness(): Strictness {
return Strictness::NOTICE;
}

public function getAppConfigs(): array {
return [
new Entry(
self::OVERWRITES_HOME_FOLDERS,
ValueType::ARRAY,
defaultRaw: [],
definition: 'List of applications overwriting home folders',
lazy: false,
note: 'It will be populated with app IDs of mount providers that overwrite home folders. Currently, only files_external and groupfolders.',
),
];
}

public function getUserConfigs(): array {
return [];
}
}
2 changes: 1 addition & 1 deletion apps/files_external/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This application enables administrators to configure connections to external sto

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.
</description>
<version>1.25.0</version>
<version>1.25.1</version>
<licence>agpl</licence>
<author>Robin Appelman</author>
<author>Michael Gapczynski</author>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'OCA\\Files_External\\Migration\\Version1011Date20200630192246' => $baseDir . '/../lib/Migration/Version1011Date20200630192246.php',
'OCA\\Files_External\\Migration\\Version1015Date20211104103506' => $baseDir . '/../lib/Migration/Version1015Date20211104103506.php',
'OCA\\Files_External\\Migration\\Version1016Date20220324154536' => $baseDir . '/../lib/Migration/Version1016Date20220324154536.php',
'OCA\\Files_External\\Migration\\Version1025Date20250228162604' => $baseDir . '/../lib/Migration/Version1025Date20250228162604.php',
'OCA\\Files_External\\Migration\\Version22000Date20210216084416' => $baseDir . '/../lib/Migration/Version22000Date20210216084416.php',
'OCA\\Files_External\\MountConfig' => $baseDir . '/../lib/MountConfig.php',
'OCA\\Files_External\\NotFoundException' => $baseDir . '/../lib/NotFoundException.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ComposerStaticInitFiles_External
'OCA\\Files_External\\Migration\\Version1011Date20200630192246' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20200630192246.php',
'OCA\\Files_External\\Migration\\Version1015Date20211104103506' => __DIR__ . '/..' . '/../lib/Migration/Version1015Date20211104103506.php',
'OCA\\Files_External\\Migration\\Version1016Date20220324154536' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date20220324154536.php',
'OCA\\Files_External\\Migration\\Version1025Date20250228162604' => __DIR__ . '/..' . '/../lib/Migration/Version1025Date20250228162604.php',
'OCA\\Files_External\\Migration\\Version22000Date20210216084416' => __DIR__ . '/..' . '/../lib/Migration/Version22000Date20210216084416.php',
'OCA\\Files_External\\MountConfig' => __DIR__ . '/..' . '/../lib/MountConfig.php',
'OCA\\Files_External\\NotFoundException' => __DIR__ . '/..' . '/../lib/NotFoundException.php',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\GlobalStoragesService;
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 GlobalStoragesService $globalStoragesServices,
private IAppConfig $appConfig,
) {
}

/**
* @param Closure(): ISchemaWrapper $schemaClosure
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$this->globalStoragesServices->updateOverwriteHomeFolders();
}
}
28 changes: 21 additions & 7 deletions apps/files_external/lib/Service/DBConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCA\Files_External\Service;

use OCP\DB\Exception;
Expand Down Expand Up @@ -64,16 +65,16 @@ public function getMountsForUser($userId, $groupIds) {
->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);
Expand All @@ -94,8 +95,8 @@ protected function modifyMountsOnDelete(string $applicableId, int $applicableTyp
->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();
Expand Down Expand Up @@ -227,7 +228,7 @@ public function addMount($mountPoint, $storageBackend, $authBackend, $priority,
'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();
Expand Down Expand Up @@ -507,4 +508,17 @@ private function decryptValue($value) {
return $value;
}
}

/**
* Check if any mountpoint is configured that overwrite the home folder
*/
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 count($result->fetchAll()) > 0;
}
}
28 changes: 28 additions & 0 deletions apps/files_external/lib/Service/StoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

use OC\Files\Cache\Storage;
use OC\Files\Filesystem;
use OCA\Files\AppInfo\Application as FilesApplication;
use OCA\Files\ConfigLexicon;
use OCA\Files_External\AppInfo\Application;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\InvalidAuth;
use OCA\Files_External\Lib\Backend\Backend;
Expand All @@ -20,6 +23,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;
Expand All @@ -40,6 +44,7 @@ public function __construct(
protected DBConfigService $dbConfig,
protected IUserMountCache $userMountCache,
protected IEventDispatcher $eventDispatcher,
protected IAppConfig $appConfig,
) {
}

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

$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);

$this->updateOverwriteHomeFolders();

return $newStorage;
}

Expand Down Expand Up @@ -425,6 +433,8 @@ public function updateStorage(StorageConfig $updatedStorage) {
}
}

$this->updateOverwriteHomeFolders();

return $this->getStorage($id);
}

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

// delete oc_storages entries and oc_filecache
Storage::cleanByMountId($id);

$this->updateOverwriteHomeFolders();
}

/**
Expand All @@ -473,4 +485,20 @@ private function getStorageId(StorageConfig $storageConfig) {
return -1;
}
}

public function updateOverwriteHomeFolders(): void {
$appIdsList = $this->appConfig->getValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS);

if ($this->dbConfig->hasHomeFolderOverwriteMount()) {
if (!in_array(Application::APP_ID, $appIdsList)) {
$appIdsList[] = Application::APP_ID;
$this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList);
}
} else {
if (in_array(Application::APP_ID, $appIdsList)) {
$appIdsList = array_values(array_filter($appIdsList, fn ($v) => $v !== Application::APP_ID));
$this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList);
}
}
}
}
12 changes: 3 additions & 9 deletions apps/files_external/lib/Service/UserGlobalStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCA\Files_External\Lib\StorageConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\IAppConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -21,23 +22,16 @@
class UserGlobalStoragesService extends GlobalStoragesService {
use UserTrait;

/**
* @param BackendService $backendService
* @param DBConfigService $dbConfig
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param IUserMountCache $userMountCache
* @param IEventDispatcher $eventDispatcher
*/
public function __construct(
BackendService $backendService,
DBConfigService $dbConfig,
IUserSession $userSession,
protected IGroupManager $groupManager,
IUserMountCache $userMountCache,
IEventDispatcher $eventDispatcher,
IAppConfig $appConfig,
) {
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig);
$this->userSession = $userSession;
}

Expand Down
10 changes: 3 additions & 7 deletions apps/files_external/lib/Service/UserStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Files_External\NotFoundException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\IAppConfig;
use OCP\IUserSession;

/**
Expand All @@ -24,22 +25,17 @@ class UserStoragesService extends StoragesService {

/**
* Create a user storages service
*
* @param BackendService $backendService
* @param DBConfigService $dbConfig
* @param IUserSession $userSession user session
* @param IUserMountCache $userMountCache
* @param IEventDispatcher $eventDispatcher
*/
public function __construct(
BackendService $backendService,
DBConfigService $dbConfig,
IUserSession $userSession,
IUserMountCache $userMountCache,
IEventDispatcher $eventDispatcher,
IAppConfig $appConfig,
) {
$this->userSession = $userSession;
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher, $appConfig);
}

protected function readDBConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class GlobalStoragesServiceTest extends StoragesServiceTestCase {
protected function setUp(): void {
parent::setUp();
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher, $this->appConfig);
}

protected function tearDown(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,12 +58,13 @@ public function clean() {
*/
abstract class StoragesServiceTestCase extends \Test\TestCase {
protected StoragesService $service;
protected BackendService $backendService;
protected BackendService&MockObject $backendService;
protected string $dataDir;
protected CleaningDBConfig $dbConfig;
protected static array $hookCalls;
protected IUserMountCache&MockObject $mountCache;
protected IEventDispatcher&MockObject $eventDispatcher;
protected IAppConfig&MockObject $appConfig;

protected function setUp(): void {
parent::setUp();
Expand All @@ -77,6 +79,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function setUp(): void {
$this->groupManager,
$this->mountCache,
$this->eventDispatcher,
$this->appConfig,
);
}

Expand Down
Loading
Loading