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(); }