Skip to content

Commit

Permalink
fix(settings): Calculate correct default quota option sizes
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Sep 3, 2024
1 parent 8d02101 commit 8f0845b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
8 changes: 7 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Folders can be configured from *Group folders* in the admin settings.
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.
]]></description>
<version>19.0.0-dev.0</version>
<version>19.0.0-dev.1</version>
<licence>agpl</licence>
<author>Robin Appelman</author>
<namespace>GroupFolders</namespace>
Expand Down Expand Up @@ -41,6 +41,12 @@ After a folder is created, the admin can give access to the folder to one or mor
<job>OCA\GroupFolders\BackgroundJob\ExpireGroupTrash</job>
</background-jobs>

<repair-steps>
<post-migration>
<step>OCA\GroupFolders\Migration\WrongDefaultQuotaRepairStep</step>
</post-migration>
</repair-steps>

<commands>
<command>OCA\GroupFolders\Command\ExpireGroup\ExpireGroupBase</command>
<command>OCA\GroupFolders\Command\ListCommand</command>
Expand Down
50 changes: 50 additions & 0 deletions lib/Migration/WrongDefaultQuotaRepairStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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 OCA\GroupFolders\Folder\FolderManager;
use OCP\DB\Exception;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class WrongDefaultQuotaRepairStep implements IRepairStep {
public function __construct(
private FolderManager $manager,
) {

}

public function getName() {
return 'Adjust Groupfolders with wrong default quotas';
}

/**
* @param IOutput $output
* @throws Exception
*/
public function run(IOutput $output): void {
foreach ($this->manager->getAllFolders() as $id => $folder) {
$quota = $folder['quota'];

$changed = false;
if ($quota === 1073741274) {
$quota = 1024 ** 3;
$changed = true;
} elseif ($quota === 10737412742) {
$quota = 1024 ** 3 * 10;
$changed = true;
}

if ($changed) {
$this->manager->setFolderQuota($id, $quota);
}
}
}
}
7 changes: 4 additions & 3 deletions src/settings/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import AdminGroupSelect from './AdminGroupSelect'
import SubAdminGroupSelect from './SubAdminGroupSelect'
import { loadState } from '@nextcloud/initial-state'

const bytesInOneGibibyte = Math.pow(1024, 3)
const defaultQuotaOptions = {
'1 GB': 1073741274,
'5 GB': 5368709120,
'10 GB': 10737412742,
'1 GB': bytesInOneGibibyte,
'5 GB': bytesInOneGibibyte * 5,
'10 GB': bytesInOneGibibyte * 10,
Unlimited: -3,
}

Expand Down

0 comments on commit 8f0845b

Please sign in to comment.