Skip to content

Conversation

@yesrod
Copy link
Contributor

@yesrod yesrod commented Jan 22, 2026

The rest of the code is already set up to treat 0 as "unlimited", as far as I can tell, but the UI elements were limiting the minimum to 1. This change allows users to specify unlimited resources for a specific server if the user is not globally limited in that resource. I've tested this on my local Pelican instance, and it works as intended.

Summary by CodeRabbit

  • Bug Fixes
    • Updated server resource input validation: CPU, memory, and disk fields can now accept zero when a user has no corresponding resource limit, instead of enforcing a minimum of 1. Existing maximum limits, hints and validations remain unchanged.

✏️ Tip: You can customize this high-level summary in your review settings.

The rest of the code is already set up to treat 0 as "unlimited", as far as I can tell, but the UI elements were limiting the minimum to 1.

This change allows users to specify unlimited resources for a specific server if the user is unlimited in that resource.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Updated minValue logic for CPU, memory, and disk input fields to be conditional: set to 1 if the user's corresponding resource limit is greater than 0, otherwise 0. MaxValue, hints, and other validations remain unchanged across two Filament files.

Changes

Cohort / File(s) Summary
Resource Field Conditional MinValue
user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php, user-creatable-servers/src/Filament/Server/Pages/ServerResourcePage.php
Replaced fixed minValue: 1 with conditional minValue: userLimit > 0 ? 1 : 0 for cpu, memory, and disk inputs. Preserves existing maxValue, hints, suffixes, and validation behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble code with twitching nose,
If limits vanish, zero grows,
Fields now welcome tiny things,
Servers hum with softer springs 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adjusting minimum resource limits from 1 to 0 for user-created servers, which aligns with the file modifications and PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f9ce60 and de20bf4.

📒 Files selected for processing (2)
  • user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php
  • user-creatable-servers/src/Filament/Server/Pages/ServerResourcePage.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • user-creatable-servers/src/Filament/Server/Pages/ServerResourcePage.php
🧰 Additional context used
🧬 Code graph analysis (1)
user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php (1)
user-creatable-servers/src/Models/UserResourceLimits.php (2)
  • getCpuLeft (40-49)
  • getMemoryLeft (51-60)
🔇 Additional comments (1)
user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php (1)

58-77: Conditional min values are consistent and match the stated “unlimited = 0” rule.

Nice alignment across CPU, memory, and disk; this makes the UI reflect the same “0 means unlimited” behavior as the backend when the user has no global limit.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
user-creatable-servers/src/Filament/Server/Pages/ServerResourcePage.php (1)

65-93: Apply the same conditional minimum here to avoid “unlimited” bypass.

The edit form now permits 0 regardless of whether the user has finite limits. If 0 means “unlimited,” this can exceed quotas. Consider mirroring the conditional minimums here as well.

✅ Suggested adjustment
                 TextInput::make('cpu')
                     ->label(trans('user-creatable-servers::strings.cpu'))
                     ->required()
                     ->live(onBlur: true)
                     ->hint(fn ($state) => $userResourceLimits->cpu > 0 ? ($maxCpu - $state . '% ' . trans('user-creatable-servers::strings.left')) : trans('user-creatable-servers::strings.unlimited'))
                     ->hintColor(fn ($state) => $userResourceLimits->cpu > 0 && $maxCpu - $state < 0 ? 'danger' : null)
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->cpu > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->cpu > 0 ? $maxCpu : null)
                     ->suffix('%'),
                 TextInput::make('memory')
                     ->label(trans('user-creatable-servers::strings.memory'))
                     ->required()
                     ->live(onBlur: true)
                     ->hint(fn ($state) => $userResourceLimits->memory > 0 ? ($maxMemory - $state . $suffix . ' ' . trans('user-creatable-servers::strings.left')) : trans('user-creatable-servers::strings.unlimited'))
                     ->hintColor(fn ($state) => $userResourceLimits->memory > 0 && $maxMemory - $state < 0 ? 'danger' : null)
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->memory > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->memory > 0 ? $maxMemory : null)
                     ->suffix($suffix),
                 TextInput::make('disk')
                     ->label(trans('user-creatable-servers::strings.disk'))
                     ->required()
                     ->live(onBlur: true)
                     ->hint(fn ($state) => $userResourceLimits->disk > 0 ? ($maxDisk - $state . $suffix . ' ' . trans('user-creatable-servers::strings.left')) : trans('user-creatable-servers::strings.unlimited'))
                     ->hintColor(fn ($state) => $userResourceLimits->disk > 0 && $maxDisk - $state < 0 ? 'danger' : null)
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->disk > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->disk > 0 ? $maxDisk : null)
                     ->suffix($suffix),
user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php (1)

58-77: Align minValue with backend validation for finite user quotas.

When a user has a finite resource limit, the backend canCreateServer() enforces per-server values > 0 by rejecting <= 0. However, the UI currently allows minValue(0) unconditionally, creating a mismatch: users can submit 0, which the backend will reject. Make minValue conditional to match backend behavior.

✅ Suggested adjustment
                TextInput::make('cpu')
                     ->label(trans('user-creatable-servers::strings.cpu'))
                     ->required()
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->cpu > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->getCpuLeft())
                     ->suffix('%'),
                 TextInput::make('memory')
                     ->label(trans('user-creatable-servers::strings.memory'))
                     ->required()
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->memory > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->getMemoryLeft())
                     ->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB'),
                 TextInput::make('disk')
                     ->label(trans('user-creatable-servers::strings.disk'))
                     ->required()
                     ->numeric()
-                    ->minValue(0)
+                    ->minValue($userResourceLimits->disk > 0 ? 1 : 0)
                     ->maxValue($userResourceLimits->getDiskLeft())
                     ->suffix(config('panel.use_binary_prefix') ? 'MiB' : 'MB'),
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0005ab0 and 1f9ce60.

📒 Files selected for processing (2)
  • user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php
  • user-creatable-servers/src/Filament/Server/Pages/ServerResourcePage.php
🧰 Additional context used
🧬 Code graph analysis (1)
user-creatable-servers/src/Filament/Components/Actions/CreateServerAction.php (1)
user-creatable-servers/src/Models/UserResourceLimits.php (2)
  • getCpuLeft (40-49)
  • getMemoryLeft (51-60)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Member

@Boy132 Boy132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with coderabbit, the minValue should be conditional.

@yesrod
Copy link
Contributor Author

yesrod commented Jan 30, 2026

Requested changes have been made.

Copy link
Member

@Boy132 Boy132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@Boy132 Boy132 merged commit cb55b45 into pelican-dev:main Jan 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants