From 329a3993c1794d50f09323d83d89c68203410ed5 Mon Sep 17 00:00:00 2001 From: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Wed, 2 Oct 2024 02:33:54 +0000 Subject: [PATCH 1/3] Add can check --- .../Resources/ServerResource/Pages/ListServers.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/Filament/Resources/ServerResource/Pages/ListServers.php b/app/Filament/Resources/ServerResource/Pages/ListServers.php index a906f6704..c94d0edc6 100644 --- a/app/Filament/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/Resources/ServerResource/Pages/ListServers.php @@ -64,9 +64,8 @@ class ListServers extends ListRecords ->searchable(), SelectColumn::make('allocation_id') ->label('Primary Allocation') - ->options(fn (Server $server) => $server->allocations->mapWithKeys( - fn ($allocation) => [$allocation->id => $allocation->address]) - ) + ->disabled(fn () => !auth()->user()->can('update server')) + ->options(fn (Server $server) => $server->allocations->mapWithKeys(fn ($allocation) => [$allocation->id => $allocation->address])) ->selectablePlaceholder(false) ->sortable(), TextColumn::make('image')->hidden(), @@ -81,12 +80,7 @@ class ListServers extends ListRecords Action::make('View') ->icon('tabler-terminal') ->url(fn (Server $server) => "/server/$server->uuid_short") - ->visible(function (Server $server) { - /** @var User $user */ - $user = auth()->user(); - - return $user->isRootAdmin() || $user->id === $server->owner_id; - }), + ->visible(fn () => auth()->user()->can('view server')), EditAction::make(), ]) ->emptyStateIcon('tabler-brand-docker') From 45b73debc23ed2216b943b13b5d8ac45d980aa00 Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:45:03 +0200 Subject: [PATCH 2/3] Switch to authorize Co-authored-by: Boy132 --- .../Resources/ServerResource/Pages/ListServers.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Filament/Resources/ServerResource/Pages/ListServers.php b/app/Filament/Resources/ServerResource/Pages/ListServers.php index c94d0edc6..f0ee09a22 100644 --- a/app/Filament/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/Resources/ServerResource/Pages/ListServers.php @@ -4,7 +4,6 @@ namespace App\Filament\Resources\ServerResource\Pages; use App\Filament\Resources\ServerResource; use App\Models\Server; -use App\Models\User; use Filament\Actions; use Filament\Resources\Pages\ListRecords; use Filament\Tables\Actions\Action; @@ -64,10 +63,14 @@ class ListServers extends ListRecords ->searchable(), SelectColumn::make('allocation_id') ->label('Primary Allocation') - ->disabled(fn () => !auth()->user()->can('update server')) + ->hidden(!auth()->user()->can('update server')) ->options(fn (Server $server) => $server->allocations->mapWithKeys(fn ($allocation) => [$allocation->id => $allocation->address])) ->selectablePlaceholder(false) ->sortable(), + TextColumn::make('allocation_id_can') + ->label('Primary Allocation') + ->hidden(auth()->user()->can('update server')) + ->state(fn (Server $server) => $server->allocation->address), TextColumn::make('image')->hidden(), TextColumn::make('backups_count') ->counts('backups') @@ -80,7 +83,7 @@ class ListServers extends ListRecords Action::make('View') ->icon('tabler-terminal') ->url(fn (Server $server) => "/server/$server->uuid_short") - ->visible(fn () => auth()->user()->can('view server')), + ->authorize(fn () => auth()->user()->can('view server')), EditAction::make(), ]) ->emptyStateIcon('tabler-brand-docker') From 6a8ff1a1863add9f41d846a77022a3bfeb81e955 Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:50:57 +0200 Subject: [PATCH 3/3] Update app/Filament/Resources/ServerResource/Pages/ListServers.php Co-authored-by: Boy132 --- app/Filament/Resources/ServerResource/Pages/ListServers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/ServerResource/Pages/ListServers.php b/app/Filament/Resources/ServerResource/Pages/ListServers.php index f0ee09a22..326499898 100644 --- a/app/Filament/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/Resources/ServerResource/Pages/ListServers.php @@ -67,7 +67,7 @@ class ListServers extends ListRecords ->options(fn (Server $server) => $server->allocations->mapWithKeys(fn ($allocation) => [$allocation->id => $allocation->address])) ->selectablePlaceholder(false) ->sortable(), - TextColumn::make('allocation_id_can') + TextColumn::make('allocation_id_readonly') ->label('Primary Allocation') ->hidden(auth()->user()->can('update server')) ->state(fn (Server $server) => $server->allocation->address),