Skip to content

Commit 94f6d14

Browse files
committed
feat(settings): Make default quota configurable
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent a304a20 commit 94f6d14

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ For entitlements, only users from those groups are selectable which have to be c
5050

5151
![advanced permission entitlement](screenshots/aclAdmin.png)
5252

53+
## Configuration parameters
54+
55+
Some settings are currently only exposed via `config/config.php`:
56+
57+
Configures the default quota used when creating new groupfolders: `'groupfolders.quota.default' => -3,`
58+
5359
## Command-line interface management and configuration (via `occ`)
5460

5561
Group folders can be configured and managed from the command-line interface (CLI). This is accomplished by using the `occ` command.

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Folders can be configured from *Group folders* in the admin settings.
1313
1414
After a folder is created, the admin can give access to the folder to one or more groups, control their write/sharing permissions and assign a quota for the folder.
1515
]]></description>
16-
<version>19.0.0-dev.0</version>
16+
<version>19.0.0-dev.1</version>
1717
<licence>agpl</licence>
1818
<author>Robin Appelman</author>
1919
<namespace>GroupFolders</namespace>

lib/Folder/FolderManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Files\Cache\ICacheEntry;
2222
use OCP\Files\IMimeTypeLoader;
2323
use OCP\Files\IRootFolder;
24+
use OCP\IConfig;
2425
use OCP\IDBConnection;
2526
use OCP\IGroupManager;
2627
use OCP\IUser;
@@ -40,6 +41,7 @@ public function __construct(
4041
private IMimeTypeLoader $mimeTypeLoader,
4142
private LoggerInterface $logger,
4243
private IEventDispatcher $eventDispatcher,
44+
private IConfig $config,
4345
) {
4446
}
4547

@@ -655,11 +657,14 @@ public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId
655657
* @throws Exception
656658
*/
657659
public function createFolder(string $mountPoint): int {
660+
$defaultQuota = $this->config->getSystemValueInt('groupfolders.quota.default', -3);
661+
658662
$query = $this->connection->getQueryBuilder();
659663

660664
$query->insert('group_folders')
661665
->values([
662-
'mount_point' => $query->createNamedParameter($mountPoint)
666+
'mount_point' => $query->createNamedParameter($mountPoint),
667+
'quota' => $defaultQuota,
663668
]);
664669
$query->executeStatement();
665670
$id = $query->getLastInsertId();

lib/Migration/Version102020Date20180806161449.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
3737
$table->addColumn('quota', 'bigint', [
3838
'notnull' => true,
3939
'length' => 6,
40-
'default' => -3,
40+
// Removed in migration Version19000Date20240903062631
41+
//'default' => -3,
4142
]);
4243
$table->setPrimaryKey(['folder_id']);
4344
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\GroupFolders\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
/**
18+
* FIXME Auto-generated migration step: Please modify to your needs!
19+
*/
20+
class Version19000Date20240903062631 extends SimpleMigrationStep {
21+
/**
22+
* @param IOutput $output
23+
* @param Closure(): ISchemaWrapper $schemaClosure
24+
* @param array $options
25+
* @return null|ISchemaWrapper
26+
*/
27+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
28+
/** @var ISchemaWrapper $schema */
29+
$schema = $schemaClosure();
30+
31+
if ($schema->hasTable('group_folders')) {
32+
$table = $schema->getTable('group_folders');
33+
$table->changeColumn('quota', [
34+
'notnull' => true,
35+
'length' => 6,
36+
'default' => null,
37+
]);
38+
}
39+
40+
return $schema;
41+
}
42+
}

tests/Folder/FolderManagerTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCP\Constants;
1111
use OCP\EventDispatcher\IEventDispatcher;
1212
use OCP\Files\IMimeTypeLoader;
13+
use OCP\IConfig;
1314
use OCP\IDBConnection;
1415
use OCP\IGroupManager;
1516
use OCP\IUser;
@@ -25,6 +26,7 @@ class FolderManagerTest extends TestCase {
2526
private IMimeTypeLoader $mimeLoader;
2627
private LoggerInterface $logger;
2728
private IEventDispatcher $eventDispatcher;
29+
private IConfig $config;
2830

2931
protected function setUp(): void {
3032
parent::setUp();
@@ -33,12 +35,18 @@ protected function setUp(): void {
3335
$this->mimeLoader = $this->createMock(IMimeTypeLoader::class);
3436
$this->logger = $this->createMock(LoggerInterface::class);
3537
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
38+
$this->config = $this->createMock(IConfig::class);
39+
$this->config->expects($this->any())
40+
->method('getSystemValueInt')
41+
->with('groupfolders.quota.default', -3)
42+
->willReturn(-3);
3643
$this->manager = new FolderManager(
3744
\OC::$server->getDatabaseConnection(),
3845
$this->groupManager,
3946
$this->mimeLoader,
4047
$this->logger,
4148
$this->eventDispatcher,
49+
$this->config,
4250
);
4351
$this->clean();
4452
}
@@ -308,7 +316,7 @@ public function testGetFoldersForUserSimple() {
308316
$db = $this->createMock(IDBConnection::class);
309317
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
310318
$manager = $this->getMockBuilder(FolderManager::class)
311-
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher])
319+
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config])
312320
->setMethods(['getFoldersForGroups'])
313321
->getMock();
314322

@@ -331,7 +339,7 @@ public function testGetFoldersForUserMerge() {
331339
$db = $this->createMock(IDBConnection::class);
332340
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
333341
$manager = $this->getMockBuilder(FolderManager::class)
334-
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher])
342+
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config])
335343
->setMethods(['getFoldersForGroups'])
336344
->getMock();
337345

@@ -367,7 +375,7 @@ public function testGetFolderPermissionsForUserMerge() {
367375
$db = $this->createMock(IDBConnection::class);
368376
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
369377
$manager = $this->getMockBuilder(FolderManager::class)
370-
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher])
378+
->setConstructorArgs([$db, $this->groupManager, $this->mimeLoader, $this->logger, $this->eventDispatcher, $this->config])
371379
->setMethods(['getFoldersForGroups'])
372380
->getMock();
373381

0 commit comments

Comments
 (0)