Fix creating api keys

This commit is contained in:
notCharles 2024-05-10 16:42:05 -04:00
parent 30a668c84a
commit f1493c5139
2 changed files with 9 additions and 19 deletions

View File

@ -21,29 +21,25 @@ class CreateApiKey extends CreateRecord
Forms\Components\Hidden::make('identifier')->default(ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION)), Forms\Components\Hidden::make('identifier')->default(ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION)),
Forms\Components\Hidden::make('token')->default(encrypt(str_random(ApiKey::KEY_LENGTH))), Forms\Components\Hidden::make('token')->default(encrypt(str_random(ApiKey::KEY_LENGTH))),
Forms\Components\Select::make('user_id') Forms\Components\Hidden::make('user_id')
->hidden()
->searchable()
->preload()
->relationship('user', 'username')
->default(auth()->user()->id) ->default(auth()->user()->id)
->required(), ->required(),
Forms\Components\Select::make('key_type') Forms\Components\Select::make('key_type')
->inlineLabel()
->options(function (ApiKey $apiKey) { ->options(function (ApiKey $apiKey) {
$originalOptions = [ $originalOptions = [
ApiKey::TYPE_NONE => 'None', //ApiKey::TYPE_NONE => 'None',
ApiKey::TYPE_ACCOUNT => 'Account', ApiKey::TYPE_ACCOUNT => 'Account',
ApiKey::TYPE_APPLICATION => 'Application', ApiKey::TYPE_APPLICATION => 'Application',
ApiKey::TYPE_DAEMON_USER => 'Daemon User', //ApiKey::TYPE_DAEMON_USER => 'Daemon User',
ApiKey::TYPE_DAEMON_APPLICATION => 'Daemon Application', //ApiKey::TYPE_DAEMON_APPLICATION => 'Daemon Application',
]; ];
return collect($originalOptions) return collect($originalOptions)
->filter(fn ($value, $key) => $key <= ApiKey::TYPE_APPLICATION || $apiKey->key_type === $key) ->filter(fn ($value, $key) => $key <= ApiKey::TYPE_APPLICATION || $apiKey->key_type === $key)
->all(); ->all();
}) })
->hidden()
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->required() ->required()
->default(ApiKey::TYPE_APPLICATION), ->default(ApiKey::TYPE_APPLICATION),
@ -56,7 +52,7 @@ class CreateApiKey extends CreateRecord
]) ])
->schema( ->schema(
collect(ApiKey::RESOURCES)->map(fn ($resource) => Forms\Components\ToggleButtons::make("r_$resource") collect(ApiKey::RESOURCES)->map(fn ($resource) => Forms\Components\ToggleButtons::make("r_$resource")
->label(str($resource)->replace('_', ' ')->title()) ->label(str($resource)->replace('_', ' ')->title())->inline()
->options([ ->options([
0 => 'None', 0 => 'None',
1 => 'Read', 1 => 'Read',
@ -75,9 +71,7 @@ class CreateApiKey extends CreateRecord
2 => 'danger', 2 => 'danger',
3 => 'danger', 3 => 'danger',
]) ])
->inline()
->required() ->required()
->disabledOn('edit')
->columnSpan([ ->columnSpan([
'default' => 1, 'default' => 1,
'sm' => 1, 'sm' => 1,

View File

@ -21,8 +21,8 @@ class ListApiKeys extends ListRecords
->searchable(false) ->searchable(false)
->columns([ ->columns([
Tables\Columns\TextColumn::make('user.username') Tables\Columns\TextColumn::make('user.username')
->searchable()
->hidden() ->hidden()
->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('key') Tables\Columns\TextColumn::make('key')
@ -53,12 +53,8 @@ class ListApiKeys extends ListRecords
// //
]) ])
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(),
]) //Tables\Actions\EditAction::make()
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]); ]);
} }