Show usage and neutral boxes for unlimited quotas (#1151)

Unlimited mailboxes currently show only the unlimited label, hiding available usage. 
Unlimited domain counters also lose their quota box, and the domain storage label continues to show assigned quota even when actual usage is available.

thanks @TrapoSAMA
This commit is contained in:
Rodrigo Cortés Cano authored and GitHub committed 2026-10-03 11:16:53 +01:00
1 parent eea8021889
commit b0fe5db364
4 files changed
+90 -3

No files matched your search

+1
View File
@@ -9,6 +9,7 @@
Changes in 'master' (not in a release yet) (20XX/XX/XX)
--------------------------
- Show available usage for unlimited quotas and retain neutral quota boxes.
- Remove the obsolete quota_usage.pl example and Horde 3 SQL password guide.
See ADDITIONS/README.md for quota integration and modernization notes.
- Restore the legacy md5crypt password scheme compatibility (see #1123, thanks @8ctopus)
+3 -1
View File
@@ -75,7 +75,9 @@
{if $CONF.quota===YES}
<td>
{if $item.quota==0}
{$PALANG.pOverview_unlimited}
<div class="quota_bar">
<span class="quota_label">{if $boolconf_used_quotas}{$divide_quota.current[$i]} / &infin;{else}&infin;{/if}</span>
</div>
{elseif $item.quota<0}
{$PALANG.pOverview_disabled}
{else}
+2 -2
View File
@@ -167,12 +167,12 @@
{if $table == 'domain' && $key == 'total_quot' && isset($item.total_quota_used)}
{assign "quota_tooltip" "{$PALANG.quota_assigned}: {$linktext}&#10;{$PALANG.quota_used}: {$item.total_quota_used} MB"}
{/if}
<div class="quota_bar{if $item[$tmpkey] <= -1} quota_no_border{/if}"{if $quota_tooltip != ''} title="{$quota_tooltip}"{/if}>
<div class="quota_bar{if $item[$tmpkey] <= -1 && !($table == 'domain' && (($key == 'aliases_quot' && $item.aliases == 0) || ($key == 'mailboxes_quot' && $item.mailboxes == 0) || ($key == 'total_quot' && $item.quota == 0)))} quota_no_border{/if}"{if $quota_tooltip != ''} title="{$quota_tooltip}"{/if}>
{if $item[$tmpkey] > -1}
<span class="quota_fill quota_{$quota_level}" style="width:{$item[$tmpkey]}%;"></span>
<span class="quota_label quota_text_{$quota_level}">{$linktext}</span>
{else}
<span class="quota_label">{$linktext}</span>
<span class="quota_label">{if $table == 'domain' && $key == 'total_quot' && $item.quota == 0 && $CONF.used_quotas === YES && isset($item.total_quota_used)}{$item.total_quota_used} / &infin;{else}{$linktext}{/if}</span>
{/if}
</div>
+84
View File
@@ -0,0 +1,84 @@
<?php
class UnlimitedQuotaTemplateTest extends \PHPUnit\Framework\TestCase
{
private function renderQuota(string $file, string $start, string $end, array $variables): string
{
if (!defined('YES')) {
define('YES', 'YES');
}
$source = file_get_contents(__DIR__ . '/../templates/' . $file);
$offset = strpos($source, $start);
self::assertNotFalse($offset);
$length = strpos($source, $end, $offset) - $offset;
$smarty = new \Smarty\Smarty();
$smarty->setCompileDir(sys_get_temp_dir());
$smarty->assign($variables);
return $smarty->fetch('string:' . substr($source, $offset, $length));
}
public function testUnlimitedMailboxRetainsAvailableAndUnknownUsage(): void
{
foreach (['0', '256', 'N/D'] as $usage) {
$html = $this->mailbox(0, true, $usage);
self::assertStringContainsString($usage . ' / &infin;', $html);
self::assertStringContainsString('class="quota_bar"', $html);
self::assertStringNotContainsString('quota_fill', $html);
}
$html = $this->mailbox(0, false, 'N/D');
self::assertStringContainsString('&infin;', $html);
self::assertStringNotContainsString('N/D', $html);
}
public function testLimitedAndDisabledMailboxBehaviorIsPreserved(): void
{
self::assertStringContainsString('quota_fill', $this->mailbox(1024, true, '256'));
self::assertStringContainsString('256 / 1024', $this->mailbox(1024, true, '256'));
self::assertStringContainsString('Disabled', $this->mailbox(-1, true, '256'));
self::assertStringNotContainsString('quota_bar', $this->mailbox(-1, true, '256'));
}
private function mailbox(int $quota, bool $tracking, string $usage): string
{
return $this->renderQuota('list-virtual_mailbox.tpl', '{if $item.quota==0}', '</td>', [
'item' => ['quota' => $quota], 'i' => 0,
'boolconf_used_quotas' => $tracking,
'divide_quota' => ['current' => [$usage], 'quota' => [1024], 'percent' => [25]],
'CONF' => ['quota_level_high_pct' => 90, 'quota_level_med_pct' => 80],
'PALANG' => ['pOverview_disabled' => 'Disabled'],
]);
}
public function testUnlimitedDomainCountersKeepNeutralBoxesAndActualUsage(): void
{
foreach (['aliases_quot', 'mailboxes_quot', 'total_quot'] as $key) {
$html = $this->domain($key, 0, true);
self::assertStringContainsString('class="quota_bar"', $html);
self::assertStringNotContainsString('quota_fill', $html);
self::assertStringContainsString($key == 'total_quot' ? '256 / &infin;' : '7 / infinity', $html);
}
$html = $this->domain('total_quot', 0, true);
self::assertStringContainsString('Assigned: 7 / infinity', $html);
self::assertStringContainsString('Used: 256 MB', $html);
self::assertStringContainsString('7 / infinity', $this->domain('total_quot', 0, false));
}
public function testFiniteAndDisabledDomainCountersKeepTheirBehavior(): void
{
foreach (['aliases_quot', 'mailboxes_quot', 'total_quot'] as $key) {
self::assertStringContainsString('quota_fill', $this->domain($key, 1024, true));
self::assertStringContainsString('quota_no_border', $this->domain($key, -1, true));
}
}
private function domain(string $key, int $limit, bool $tracking): string
{
return $this->renderQuota('list.tpl', '{assign "tmpkey" "_{$key}_percent"}', "{elseif \$field.type == 'txtl'}", [
'key' => $key, 'table' => 'domain', 'linktext' => '7 / infinity',
'item' => ['aliases' => $limit, 'mailboxes' => $limit, 'quota' => $limit,
'_' . $key . '_percent' => $limit > 0 ? 25 : -1, 'total_quota_used' => 256],
'CONF' => ['used_quotas' => $tracking ? 'YES' : 'NO', 'quota_level_high_pct' => 90, 'quota_level_med_pct' => 80],
'PALANG' => ['quota_assigned' => 'Assigned', 'quota_used' => 'Used'],
]);
}
}