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
38 changes: 38 additions & 0 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\GroupFolders\ACL\UserMapping\IUserMapping;
use OCA\GroupFolders\ACL\UserMapping\IUserMappingManager;
use OCA\GroupFolders\ACL\UserMapping\UserMapping;
use OCA\GroupFolders\AppInfo\Application;
use OCA\GroupFolders\Mount\FolderStorageManager;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\GroupFolders\ResponseDefinitions;
Expand All @@ -29,6 +30,7 @@
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
Expand Down Expand Up @@ -64,6 +66,7 @@ public function __construct(
private readonly IConfig $config,
private readonly IUserMappingManager $userMappingManager,
private readonly FolderStorageManager $folderStorageManager,
private readonly IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -679,6 +682,8 @@ public function createFolder(string $mountPoint): int {

$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('A new groupfolder "%s" was created with id %d', [$mountPoint, $id]));

$this->updateOverwriteHomeFolders();

return $id;
}

Expand Down Expand Up @@ -790,6 +795,8 @@ public function removeFolder(int $folderId): void {
$query->executeStatement();

$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('The groupfolder with id %d was removed', [$folderId]));

$this->updateOverwriteHomeFolders();
}

/**
Expand Down Expand Up @@ -818,6 +825,8 @@ public function renameFolder(int $folderId, string $newMountPoint): void {
$query->executeStatement();

$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('The groupfolder with id %d was renamed to "%s"', [$folderId, $newMountPoint]));

$this->updateOverwriteHomeFolders();
}

/**
Expand Down Expand Up @@ -983,4 +992,33 @@ private function getRealQuota(int $quota): int {

return $quota;
}

/**
* Check if any mountpoint is configured that overwrite the home folder
*/
private function hasHomeFolderOverwriteMount(): bool {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('folder_id')
->from('group_folders')
->where($builder->expr()->eq('mount_point', $builder->createNamedParameter('/')))
->setMaxResults(1);
$result = $query->executeQuery();
return $result->rowCount() > 0;
}

public function updateOverwriteHomeFolders(): void {
$appIdsList = $this->appConfig->getValueArray('files', 'overwrites_home_folders');

if ($this->hasHomeFolderOverwriteMount()) {
if (!in_array(Application::APP_ID, $appIdsList)) {
$appIdsList[] = Application::APP_ID;
$this->appConfig->setValueArray('files', '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('files', 'overwrites_home_folders', $appIdsList);
}
}
}
}
37 changes: 37 additions & 0 deletions lib/Migration/Version21000Date20250925152053.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\GroupFolders\Migration;

use Closure;
use OCA\GroupFolders\Folder\FolderManager;
use OCP\DB\ISchemaWrapper;
use OCP\IAppConfig;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version21000Date20250925152053 extends SimpleMigrationStep {
public function __construct(
private FolderManager $folderManager,
private IAppConfig $appConfig,
) {
}

/**
* @param Closure(): ISchemaWrapper $schemaClosure
*/
#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$this->folderManager->updateOverwriteHomeFolders();
}
}
11 changes: 8 additions & 3 deletions tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeLoader;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
Expand All @@ -42,6 +43,7 @@ class FolderManagerTest extends TestCase {
private IConfig&MockObject $config;
private IUserMappingManager&MockObject $userMappingManager;
private FolderStorageManager $folderStorageManager;
private IAppConfig $appConfig;

protected function setUp(): void {
parent::setUp();
Expand All @@ -52,7 +54,9 @@ protected function setUp(): void {
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->config = $this->createMock(IConfig::class);
$this->userMappingManager = $this->createMock(IUserMappingManager::class);
$this->userMappingManager = $this->createMock(IUserMappingManager::class);
$this->folderStorageManager = Server::get(FolderStorageManager::class);
$this->appConfig = Server::get(IAppConfig::class);

$this->manager = new FolderManager(
Server::get(IDBConnection::class),
Expand All @@ -63,6 +67,7 @@ protected function setUp(): void {
$this->config,
$this->userMappingManager,
$this->folderStorageManager,
$this->appConfig,
);
$this->clean();
}
Expand Down Expand Up @@ -363,7 +368,7 @@ public function testGetFoldersForUserEmpty(): void {
public function testGetFoldersForUserSimple(): void {
$db = $this->createMock(IDBConnection::class);
$manager = $this->getMockBuilder(FolderManager::class)
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager])
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager, $this->appConfig])
->onlyMethods(['getFoldersForGroups'])
->getMock();

Expand Down Expand Up @@ -392,7 +397,7 @@ public function testGetFoldersForUserSimple(): void {
public function testGetFoldersForUserMerge(): void {
$db = $this->createMock(IDBConnection::class);
$manager = $this->getMockBuilder(FolderManager::class)
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager])
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager, $this->appConfig])
->onlyMethods(['getFoldersForGroups'])
->getMock();

Expand Down Expand Up @@ -443,7 +448,7 @@ public function testGetFoldersForUserMerge(): void {
public function testGetFolderPermissionsForUserMerge(): void {
$db = $this->createMock(IDBConnection::class);
$manager = $this->getMockBuilder(FolderManager::class)
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager])
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config, $this->userMappingManager, $this->folderStorageManager, $this->appConfig])
->onlyMethods(['getFoldersForGroups'])
->getMock();

Expand Down
Loading