Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat(settings): Make default quota configurable #3162

Merged
merged 2 commits into from
Sep 3, 2024
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
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
8 changes: 7 additions & 1 deletion lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\GroupFolders\Service\FoldersFilter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
Expand Down Expand Up @@ -145,10 +146,15 @@ private function getRootFolderStorageId(): ?int {
/**
* @RequireGroupFolderAdmin
* @NoAdminRequired
* @throws OCSNotFoundException
*/
public function addFolder(string $mountpoint): DataResponse {
$id = $this->manager->createFolder(trim($mountpoint));
return new DataResponse(['id' => $id]);
$folder = $this->manager->getFolder($id, $this->rootFolder->getMountPoint()->getNumericStorageId());
if ($folder === false) {
throw new OCSNotFoundException();
}
return new DataResponse($folder);
}

/**
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;
}
}
4 changes: 2 additions & 2 deletions src/settings/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export class Api {
}).then((data) => data.data)
}

createFolder(mountPoint: string): Thenable<number> {
createFolder(mountPoint: string): Thenable<Folder> {
return $.post(this.getUrl('folders'), {
mountpoint: mountPoint
}, null, 'json').then((data: OCSResult<{ id: number; }>) => data.ocs.data.id)
}, null, 'json').then((data: OCSResult<Folder>) => data.ocs.data)
}

deleteFolder(id: number): Thenable<void> {
Expand Down
12 changes: 2 additions & 10 deletions src/settings/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,9 @@ export class App extends Component<{}, AppState> implements OC.Plugin<OC.Search.
return
}
this.setState({ newMountPoint: '' })
this.api.createFolder(mountPoint).then((id) => {
this.api.createFolder(mountPoint).then((folder) => {
const folders = this.state.folders
folders.push({
mount_point: mountPoint,
groups: {},
quota: -3,
size: 0,
id,
acl: false,
manage: [],
})
folders.push(folder)
this.setState({ folders })
})
}
Expand Down
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
Loading