diff --git a/README.md b/README.md index 7d6c4a9d6..d3a9a5ce4 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,18 @@ For entitlements, only users from those groups are selectable which have to be c ![advanced permission entitlement](screenshots/aclAdmin.png) +## Configuration parameters + +Some settings are currently only exposed via `config/config.php`: + +### Default quota for new groupfolders + +```injectablephp +'groupfolders.quota.default' => -3, +``` + +The special value `-3` means unlimited and any other value is the quota limit in bytes. + ## Command-line interface management and configuration (via `occ`) Group folders can be configured and managed from the command-line interface (CLI). This is accomplished by using the `occ` command. diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index f51cf9161..396f0e8dc 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -21,6 +21,7 @@ use OCP\Files\Cache\ICacheEntry; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; @@ -40,6 +41,7 @@ public function __construct( private IMimeTypeLoader $mimeTypeLoader, private LoggerInterface $logger, private IEventDispatcher $eventDispatcher, + private IConfig $config, ) { } @@ -655,11 +657,14 @@ public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId * @throws Exception */ public function createFolder(string $mountPoint): int { + $defaultQuota = $this->config->getSystemValueInt('groupfolders.quota.default', -3); + $query = $this->connection->getQueryBuilder(); $query->insert('group_folders') ->values([ - 'mount_point' => $query->createNamedParameter($mountPoint) + 'mount_point' => $query->createNamedParameter($mountPoint), + 'quota' => $defaultQuota, ]); $query->executeStatement(); $id = $query->getLastInsertId(); diff --git a/lib/Migration/Version102020Date20180806161449.php b/lib/Migration/Version102020Date20180806161449.php index 6a07693d3..9aef4de68 100644 --- a/lib/Migration/Version102020Date20180806161449.php +++ b/lib/Migration/Version102020Date20180806161449.php @@ -37,7 +37,8 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op $table->addColumn('quota', 'bigint', [ 'notnull' => true, 'length' => 6, - 'default' => -3, + // Removed in migration Version19000Date20240903062631 + //'default' => -3, ]); $table->setPrimaryKey(['folder_id']); } diff --git a/lib/Migration/Version19000Date20240903062631.php b/lib/Migration/Version19000Date20240903062631.php new file mode 100644 index 000000000..1fb1b10e4 --- /dev/null +++ b/lib/Migration/Version19000Date20240903062631.php @@ -0,0 +1,42 @@ +hasTable('group_folders')) { + $table = $schema->getTable('group_folders'); + $table->changeColumn('quota', [ + 'notnull' => true, + 'length' => 6, + 'default' => null, + ]); + } + + return $schema; + } +} diff --git a/tests/Folder/FolderManagerTest.php b/tests/Folder/FolderManagerTest.php index f09563805..19b2afd4c 100644 --- a/tests/Folder/FolderManagerTest.php +++ b/tests/Folder/FolderManagerTest.php @@ -10,6 +10,7 @@ use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IMimeTypeLoader; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; @@ -25,6 +26,7 @@ class FolderManagerTest extends TestCase { private IMimeTypeLoader $mimeLoader; private LoggerInterface $logger; private IEventDispatcher $eventDispatcher; + private IConfig $config; protected function setUp(): void { parent::setUp(); @@ -33,12 +35,18 @@ protected function setUp(): void { $this->mimeLoader = $this->createMock(IMimeTypeLoader::class); $this->logger = $this->createMock(LoggerInterface::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); + $this->config = $this->createMock(IConfig::class); + $this->config->expects($this->any()) + ->method('getSystemValueInt') + ->with('groupfolders.quota.default', -3) + ->willReturn(-3); $this->manager = new FolderManager( \OC::$server->getDatabaseConnection(), $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, + $this->config, ); $this->clean(); } @@ -308,7 +316,7 @@ public function testGetFoldersForUserSimple() { $db = $this->createMock(IDBConnection::class); /** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */ $manager = $this->getMockBuilder(FolderManager::class) - ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher]) + ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config]) ->setMethods(['getFoldersForGroups']) ->getMock(); @@ -331,7 +339,7 @@ public function testGetFoldersForUserMerge() { $db = $this->createMock(IDBConnection::class); /** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */ $manager = $this->getMockBuilder(FolderManager::class) - ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher]) + ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config]) ->setMethods(['getFoldersForGroups']) ->getMock(); @@ -367,7 +375,7 @@ public function testGetFolderPermissionsForUserMerge() { $db = $this->createMock(IDBConnection::class); /** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */ $manager = $this->getMockBuilder(FolderManager::class) - ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher]) + ->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config]) ->setMethods(['getFoldersForGroups']) ->getMock();