Add can check

This commit is contained in:
RMartinOscar 2024-10-02 02:33:54 +00:00
parent 6c205a744d
commit 329a3993c1

View File

@ -64,9 +64,8 @@ class ListServers extends ListRecords
->searchable(), ->searchable(),
SelectColumn::make('allocation_id') SelectColumn::make('allocation_id')
->label('Primary Allocation') ->label('Primary Allocation')
->options(fn (Server $server) => $server->allocations->mapWithKeys( ->disabled(fn () => !auth()->user()->can('update server'))
fn ($allocation) => [$allocation->id => $allocation->address]) ->options(fn (Server $server) => $server->allocations->mapWithKeys(fn ($allocation) => [$allocation->id => $allocation->address]))
)
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->sortable(), ->sortable(),
TextColumn::make('image')->hidden(), TextColumn::make('image')->hidden(),
@ -81,12 +80,7 @@ class ListServers extends ListRecords
Action::make('View') Action::make('View')
->icon('tabler-terminal') ->icon('tabler-terminal')
->url(fn (Server $server) => "/server/$server->uuid_short") ->url(fn (Server $server) => "/server/$server->uuid_short")
->visible(function (Server $server) { ->visible(fn () => auth()->user()->can('view server')),
/** @var User $user */
$user = auth()->user();
return $user->isRootAdmin() || $user->id === $server->owner_id;
}),
EditAction::make(), EditAction::make(),
]) ])
->emptyStateIcon('tabler-brand-docker') ->emptyStateIcon('tabler-brand-docker')