From 879bd5c42a10b8876335bf18a05c02ea19b5eb12 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 10 Nov 2026 15:51:43 +0100 Subject: [PATCH] fix(api-tokens): open the tokens page when a token has unreadable scopes Co-Authored-By: Claude Opus 5.5 --- .changes/crashed-the-keys-tokens-api-tokens.md | 4 ++++ app/Livewire/Forms/ApiTokenForm.php | 3 ++- app/Livewire/Security/ApiTokens.php | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/crashed-the-keys-tokens-api-tokens.md diff --git a/.changes/crashed-the-keys-tokens-api-tokens.md b/.changes/crashed-the-keys-tokens-api-tokens.md new file mode 100644 index 0000000000..b9005bf276 --- /dev/null +++ b/.changes/crashed-the-keys-tokens-api-tokens.md @@ -0,0 +1,4 @@ +--- +type: fixed +--- +Crashed the `Keys & Tokens` > `API Tokens` page with a 500 error for a token with scopes stored in an unexpected format diff --git a/app/Livewire/Forms/ApiTokenForm.php b/app/Livewire/Forms/ApiTokenForm.php index dc5c309024..afa1874bbb 100644 --- a/app/Livewire/Forms/ApiTokenForm.php +++ b/app/Livewire/Forms/ApiTokenForm.php @@ -2,6 +2,7 @@ namespace App\Livewire\Forms; +use App\Services\Access\Grant; use Laravel\Sanctum\PersonalAccessToken; use Livewire\Form; @@ -55,7 +56,7 @@ class ApiTokenForm extends Form 'description' => $token->name, 'permissions' => $permissions, 'scopeMode' => $token->scopes === null ? 'team' : 'selected', - 'selectedScopes' => collect($token->scopes ?? [])->map(fn (array $scope) => "{$scope['scope']}:{$scope['uuid']}")->values()->all(), + 'selectedScopes' => array_map(fn (Grant $scope) => "{$scope->scope->value}:{$scope->uuid}", Grant::listFrom($token->scopes)), 'expiresInDays' => self::KEEP_EXPIRY, 'keepLabel' => 'Keep current ('.($token->expires_at?->isPast() ? 'expired '.$currentExpiry : $currentExpiry).')', ]; diff --git a/app/Livewire/Security/ApiTokens.php b/app/Livewire/Security/ApiTokens.php index 566e42a0d2..6516422f3f 100644 --- a/app/Livewire/Security/ApiTokens.php +++ b/app/Livewire/Security/ApiTokens.php @@ -174,7 +174,7 @@ class ApiTokens extends Component 'search' => Str::lower(collect([$token->name, ...($token->abilities ?? [])]) ->merge($token->scopes === null ? ['All resources in the team'] - : collect($token->scopes)->map(fn ($scope) => $scopeLabels[($scope['scope'] ?? '').':'.($scope['uuid'] ?? '')] ?? null)->filter()) + : collect(Grant::listFrom($token->scopes))->map(fn (Grant $scope) => $scopeLabels[$scope->scope->value.':'.$scope->uuid] ?? null)->filter()) ->join(' ')), ])->values()->all(); }