Skip to content

Commit

Permalink
feat(settings): Make default quota configurable
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>

[skip ci]
  • Loading branch information
provokateurin authored and backportbot[bot] committed Sep 3, 2024
1 parent 156fe95 commit ce8972a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +41,7 @@ public function __construct(
private IMimeTypeLoader $mimeTypeLoader,
private LoggerInterface $logger,
private IEventDispatcher $eventDispatcher,
private IConfig $config,
) {
}

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion lib/Migration/Version102020Date20180806161449.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
42 changes: 42 additions & 0 deletions lib/Migration/Version19000Date20240903062631.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

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

namespace OCA\GroupFolders\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version19000Date20240903062631 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('group_folders')) {
$table = $schema->getTable('group_folders');
$table->changeColumn('quota', [
'notnull' => true,
'length' => 6,
'default' => null,
]);
}

return $schema;
}
}
14 changes: 11 additions & 3 deletions tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ce8972a

Please sign in to comment.