Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Sep 18, 2025

Closes #1717

@Boy132 Boy132 self-assigned this Sep 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

📝 Walkthrough

Walkthrough

Removed explicit return types from several TextColumn URL closures. Reworked primary-allocation UI in the Users relation manager: renamed allocation column, split editable vs read-only columns with permission and allocations-count based visibility/disabled logic, updated options/placeholder behavior, and removed an unused image column.

Changes

Cohort / File(s) Summary of Changes
Admin servers list URL closures
app/Filament/Admin/Resources/Servers/Pages/ListServers.php
Removed explicit string return type hints from three TextColumn::->url closures (node.name, egg.name, user.username). No other column logic changed.
User servers relation manager — allocation UI & URLs
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php
Dropped explicit return types from TextColumn::->url closures (name, node.name, egg.name). Renamed SelectColumn::make('allocation.id')SelectColumn::make('allocation_id'). Reworked primary allocation into two columns: allocation_id (editable) — hidden when user lacks update permission, disabled when allocations count ≤ 1, options use all allocations, selectablePlaceholder set by count; and allocation_id_readonly (shown when user cannot update) — displays primary allocation address or translatable 'None', disabled when allocations ≤ 1. Removed previously hidden image column. Added TODO note to switch to policy-based checks. databases_count made numeric and sortable.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Admin as Admin User
  participant UI as Users → Servers RelationManager
  participant Auth as Authorization
  participant S as Server Model

  Admin->>UI: Open User edit → Servers tab
  UI->>Auth: check permission can('update server')
  alt permission granted
    UI->>S: load server.allocations
    note right of UI: Render SelectColumn `allocation_id`<br/>Options = all allocations<br/>Disabled if allocations ≤ 1
  else permission denied
    UI->>S: load server.allocation (primary)
    note right of UI: Render TextColumn `allocation_id_readonly`<br/>State = address or 'None'<br/>Disabled if allocations ≤ 1
  end
Loading

Pre-merge checks

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The diff contains several edits that are not required to fix issue [#1717], including removal of explicit return type hints in TextColumn url closures and a translation tweak in ListServers.php, removal of the image TextColumn, and cosmetic numeric/sortable adjustments to databases_count; these refactors and UI tweaks fall outside the linked issue's scope. Please split non-essential refactors and cosmetic changes into a separate PR or add a short justification in this PR explaining why they were included and how they were tested; if the image column removal was accidental, restore it before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title succinctly and accurately describes the primary change — enabling the allocation selector in the Users' servers relation manager — and maps directly to the modifications in the Users RelationManager file, so it is clear and on-topic.
Linked Issues Check ✅ Passed The changes address the core requirement of issue [#1717] by making the allocation selector editable in the user's server relation manager: the select column is renamed to allocation_id, its disabled() predicate now only disables when the server has one or no allocations, the options include all allocations, and a read-only allocation_id_readonly is shown when the user lacks update permission. These edits directly implement the expected behavior that the primary allocation can be changed from the user's server list when multiple allocations exist and the user has permission. The remaining TODO to switch the permission check to a policy is noted but does not prevent this change from meeting the issue objective.
Description Check ✅ Passed The PR description "Closes #1717" directly links the change to the reported issue and is therefore related to the changeset, so this lenient check passes despite the description being minimal.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8058c63 and 1677ea2.

📒 Files selected for processing (2)
  • app/Filament/Admin/Resources/Servers/Pages/ListServers.php (2 hunks)
  • app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Filament/Admin/Resources/Servers/Pages/ListServers.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T17:33:57.388Z
Learnt from: lancepioch
PR: pelican-dev/panel#1595
File: app/Services/Servers/ServerCreationService.php:182-184
Timestamp: 2025-08-12T17:33:57.388Z
Learning: In the Pelican Panel codebase, when updating allocations to assign them to servers, the preferred pattern is to use whereNull('server_id'), lockForUpdate(), and direct property assignment with save() rather than mass update methods, to prevent race conditions and mass-assignment issues while ensuring model events fire properly.

Applied to files:

  • app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php
🧬 Code graph analysis (1)
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (1)
app/Models/Server.php (2)
  • Server (132-504)
  • allocation (277-280)
🔇 Additional comments (4)
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (4)

57-59: URLs for server edit look good.

Closure is concise; route target and params are correct.


62-63: URLs for node edit look good.

Consistent with Filament resource routing.


66-67: URLs for egg edit look good.

Matches the pattern used elsewhere.


76-80: Read‑only primary allocation display looks good.

Correct fallback to translation when no primary allocation; leverages eager‑loaded allocation.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

@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: 1

Caution

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

⚠️ Outside diff range comments (2)
app/Filament/Admin/Resources/Servers/Pages/ListServers.php (2)

79-82: Remove unsupported TextColumn::disabled() and localize 'None'

TextColumn in Filament v3 has no disabled() method — remove that call (use the existing hidden() toggle) and replace the literal 'None' with a translation.

-                    ->disabled(fn (Server $server) => $server->allocations->count() <= 1)
-                    ->state(fn (Server $server) => $server->allocation->address ?? 'None'),
+                    ->state(fn (Server $server) => $server->allocation->address ?? trans('admin/server.none')),

71-75: Eager‑load allocations on the ListServers table to avoid an N+1.

Both the SelectColumn and TextColumn call $server->allocations per row — add a query modifier in table() to load allocations once, e.g.:

->modifyQueryUsing(fn (Illuminate\Database\Eloquent\Builder $query) => $query->with('allocations'));

Location: app/Filament/Admin/Resources/Servers/Pages/ListServers.php (inside table() return chain).

🧹 Nitpick comments (1)
app/Filament/Admin/Resources/Servers/Pages/ListServers.php (1)

54-54: URL closures without return types — OK; keep style consistent.

Change is fine. Consider making nearby closures consistent (either all typed or all untyped) for static analysis/readability.

Also applies to: 60-60, 66-66

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce393af and 8058c63.

📒 Files selected for processing (2)
  • app/Filament/Admin/Resources/Servers/Pages/ListServers.php (1 hunks)
  • app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: lancepioch
PR: pelican-dev/panel#1595
File: app/Services/Servers/ServerCreationService.php:182-184
Timestamp: 2025-08-12T17:33:57.388Z
Learning: In the Pelican Panel codebase, when updating allocations to assign them to servers, the preferred pattern is to use whereNull('server_id'), lockForUpdate(), and direct property assignment with save() rather than mass update methods, to prevent race conditions and mass-assignment issues while ensuring model events fire properly.
🧬 Code graph analysis (2)
app/Filament/Admin/Resources/Servers/Pages/ListServers.php (3)
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (1)
  • table (20-92)
app/Filament/Admin/Resources/Eggs/RelationManagers/ServersRelationManager.php (1)
  • table (15-43)
app/Filament/Admin/Resources/Nodes/RelationManagers/NodesRelationManager.php (1)
  • table (22-61)
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (1)
app/Models/Server.php (2)
  • Server (132-504)
  • allocation (277-280)
🔇 Additional comments (3)
app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (3)

57-57: URL closures without return types — OK.

No behavior change; aligns with other spots in the PR.

Also applies to: 62-62, 66-66


68-75: Use per-record policy check for column visibility

Replace the global ability check with a per-record policy when the hidden() callback can receive the record: change
->hidden(fn () => !auth()->user()->can('update server'))
to
->hidden(fn (Server $server) => !auth()->user()->can('update', $server))
(or Gate::allows('update', $server)). If your Filament version doesn't pass the record into hidden(), keep the current code and retain the TODO.

File: app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php — lines 68–75


76-80: Keep ->disabled(); localize fallback and fix hidden() policy check

  • TextColumn::disabled(...) is supported in Filament Tables v3 — do not remove the ->disabled(...) call.
  • Localize the fallback: change ->state(fn (Server $server) => $server->allocation->address ?? 'None') to ->state(fn (Server $server) => $server->allocation->address ?? trans('admin/server.none')).
  • Fix the hidden() permission check: current ->hidden(fn () => auth()->user()->can('update server')) is wrong (no Server passed and wrong ability usage). Use a policy check that receives the record and hide when the user cannot update it, e.g. ->hidden(fn (?Server $server) => !auth()->user()->can('update', $server)).

File: app/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.php (lines 76-80)

Likely an incorrect or invalid review comment.

@Boy132 Boy132 merged commit c10280a into main Sep 19, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/fix-allocation-select branch September 19, 2025 06:43
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing primary allocation through user view not possible

3 participants