Cleanup, fix and expand various relation managers and lists#2456
Cleanup, fix and expand various relation managers and lists#2456Boy132 wants to merge 5 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFilament admin tables and relation managers now use authorization-aware edit links, shared console actions, revised allocation controls, updated icons and headings, and additional sorting, searching, and column visibility behavior. ChangesAdmin UI behavior
Sequence Diagram(s)sequenceDiagram
actor Admin
participant FilamentTable
participant ViewConsoleAction
participant Server
Admin->>FilamentTable: select server action
FilamentTable->>ViewConsoleAction: resolve server
ViewConsoleAction->>Server: verify tenant access and build console URL
Server-->>Admin: provide console URL
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
app/Filament/Admin/Resources/Servers/Pages/ListServers.php (1)
74-85: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winFix global
hiddentoggle and address TODO.The
hidden()method on table columns is evaluated globally per-table, meaning it doesn't receive a specific$serverinstance to check permissions against. Toggling between two columns based on a global permission breaks if permissions vary per record.To evaluate permissions per-record (resolving the TODO), consolidate this into a single
SelectColumnand use thedisabled()method instead. Additionally, the PR summary mentions disabling native select behavior, so you should append->native(false)to finalize that objective.💡 Proposed fix
SelectColumn::make('allocation_id') ->label(trans('admin/server.primary_allocation')) - ->hidden(fn () => !user()?->can('update server')) // TODO: update to policy check (fn (Server $server) --> $server is empty) - ->disabled(fn (Server $server) => $server->allocations->count() <= 1) + ->disabled(fn (Server $server) => !user()?->can('update', $server) || $server->allocations->count() <= 1) ->options(fn (Server $server) => $server->allocations->mapWithKeys(fn ($allocation) => [$allocation->id => $allocation->address])) ->selectablePlaceholder(fn (Server $server) => $server->allocations->count() <= 1) ->placeholder(trans('admin/server.none')) + ->native(false) ->sortable(), - TextColumn::make('allocation_id_readonly') - ->label(trans('admin/server.primary_allocation')) - ->hidden(fn () => user()?->can('update server')) // TODO: update to policy check (fn (Server $server) --> $server is empty) - ->state(fn (Server $server) => $server->allocation->address ?? trans('admin/server.none')),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Filament/Admin/Resources/Servers/Pages/ListServers.php` around lines 74 - 85, Replace the paired allocation columns with a single SelectColumn for allocation_id; remove the global hidden callbacks and readonly TextColumn, and use the record-aware disabled callback to prevent editing when the current Server cannot be updated while preserving the existing allocation options and placeholder behavior. Append native(false) to the SelectColumn configuration.app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php (1)
116-126: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick winPrevent mass updating all unassigned allocations globally.
The
afterclosure forDissociateBulkActionexecutes an unrestricted update query:Allocation::whereNull('server_id')->update(...). This will unintentionally wipe out thenotesand unlock every unassigned allocation in the entire database, not just the specific allocations that were selected for dissociation.To affect only the selected records, accept the
$recordscollection in the closure and scope the update explicitly to those IDs.💡 Proposed fix
DissociateBulkAction::make() - ->after(function () { - Allocation::whereNull('server_id')->update([ + ->after(function (\Illuminate\Database\Eloquent\Collection $records) { + Allocation::whereIn('id', $records->pluck('id'))->update([ 'notes' => null, 'is_locked' => false, ]); if (!$this->getOwnerRecord()->allocation_id) { $this->getOwnerRecord()->update(['allocation_id' => $this->getOwnerRecord()->allocations()->first()?->id]); } }),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php` around lines 116 - 126, Update the DissociateBulkAction after closure to accept the selected $records collection and restrict the Allocation update to those records’ IDs while retaining the existing notes and is_locked values. Remove the global whereNull-only update, and preserve the owner allocation_id fallback logic.app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php (1)
115-136: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winIncorrect Action classes used in Form Schemas.
Both files incorrectly reuse the Table Action namespace inside the Create form schema. In Filament, actions passed to form methods like
hintActionandsuffixActionMUST be instances ofFilament\Forms\Components\Actions\Action. UsingFilament\Tables\Actions\Action(or Page Actions) inside a form component will result in aTypeError.To fix this, alias the Form Action in your imports (e.g.,
use Filament\Forms\Components\Actions\Action as FormAction;) and update the schemas:
app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php#L115-L136: ChangeAction::make('hint_refresh')andAction::make('custom_ip')toFormAction::make(...).app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php#L142-L161: ChangeAction::make('refresh')andAction::make('custom_ip')toFormAction::make(...).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php` around lines 115 - 136, Replace the table/page Action import with an aliased Filament form action in both allocation relation managers. In app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php lines 115-136, use FormAction for hint_refresh and custom_ip; likewise in app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php lines 142-161, use FormAction for refresh and custom_ip.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php`:
- Around line 14-16: Replace the Filament\Actions imports used by the relation
manager’s recordActions and toolbarActions with the corresponding
Filament\Tables\Actions equivalents, including Action, CreateAction, and
DeleteAction. Leave the table configuration behavior unchanged.
In
`@app/Filament/Admin/Resources/Nodes/RelationManagers/ServersRelationManager.php`:
- Around line 40-44: Update the name column’s URL callback in the
ServersRelationManager to authorize and link to the server’s edit page using the
server record and its edit-page URL, rather than the node’s EditNode URL.
Preserve the existing permission check and null URL behavior when unauthorized.
---
Outside diff comments:
In
`@app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php`:
- Around line 115-136: Replace the table/page Action import with an aliased
Filament form action in both allocation relation managers. In
app/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.php
lines 115-136, use FormAction for hint_refresh and custom_ip; likewise in
app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php
lines 142-161, use FormAction for refresh and custom_ip.
In `@app/Filament/Admin/Resources/Servers/Pages/ListServers.php`:
- Around line 74-85: Replace the paired allocation columns with a single
SelectColumn for allocation_id; remove the global hidden callbacks and readonly
TextColumn, and use the record-aware disabled callback to prevent editing when
the current Server cannot be updated while preserving the existing allocation
options and placeholder behavior. Append native(false) to the SelectColumn
configuration.
In
`@app/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.php`:
- Around line 116-126: Update the DissociateBulkAction after closure to accept
the selected $records collection and restrict the Allocation update to those
records’ IDs while retaining the existing notes and is_locked values. Remove the
global whereNull-only update, and preserve the owner allocation_id fallback
logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 14b6d7bf-3972-4d7e-a316-b66ddc9c279e
📒 Files selected for processing (15)
app/Filament/Admin/Resources/DatabaseHosts/RelationManagers/DatabasesRelationManager.phpapp/Filament/Admin/Resources/Eggs/Pages/ListEggs.phpapp/Filament/Admin/Resources/Eggs/RelationManagers/ServersRelationManager.phpapp/Filament/Admin/Resources/Nodes/Pages/ListNodes.phpapp/Filament/Admin/Resources/Nodes/RelationManagers/AllocationsRelationManager.phpapp/Filament/Admin/Resources/Nodes/RelationManagers/ServersRelationManager.phpapp/Filament/Admin/Resources/Servers/Pages/ListServers.phpapp/Filament/Admin/Resources/Servers/RelationManagers/AllocationsRelationManager.phpapp/Filament/Admin/Resources/Servers/RelationManagers/DatabasesRelationManager.phpapp/Filament/Admin/Resources/Users/RelationManagers/ServersRelationManager.phpapp/Filament/Admin/Resources/Users/UserResource.phpapp/Filament/Components/Actions/ViewConsoleAction.phpapp/Providers/Filament/FilamentServiceProvider.phplang/en/admin/node.phplang/en/admin/server.php
💤 Files with no reviewable changes (1)
- app/Filament/Admin/Resources/Nodes/Pages/ListNodes.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/Filament/Admin/Resources/Nodes/RelationManagers/ServersRelationManager.php`:
- Line 41: Update the URL callback in the ServersRelationManager table
configuration to pass the defined $server variable to the user()->can('update',
...) authorization check, while preserving the existing EditServer URL and null
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0605b1ff-0eab-4a3b-90aa-9b38e5d3b5e6
📒 Files selected for processing (1)
app/Filament/Admin/Resources/Nodes/RelationManagers/ServersRelationManager.php
A bunch of smaller changes that improve our relation managers and lists.
This also includes fixes for actions and authorize checks.