mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 14:24:46 +02:00
Merge pull request #302 from pelican-dev/issue/294
Only show application api keys
This commit is contained in:
commit
cb638369cf
@ -4,9 +4,7 @@ namespace App\Filament\Resources;
|
|||||||
|
|
||||||
use App\Filament\Resources\ApiKeyResource\Pages;
|
use App\Filament\Resources\ApiKeyResource\Pages;
|
||||||
use App\Models\ApiKey;
|
use App\Models\ApiKey;
|
||||||
use Filament\Resources\Components\Tab;
|
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
class ApiKeyResource extends Resource
|
class ApiKeyResource extends Resource
|
||||||
{
|
{
|
||||||
@ -16,7 +14,7 @@ class ApiKeyResource extends Resource
|
|||||||
|
|
||||||
public static function getNavigationBadge(): ?string
|
public static function getNavigationBadge(): ?string
|
||||||
{
|
{
|
||||||
return static::getModel()::count() ?: null;
|
return static::getModel()::where('key_type', '2')->count() ?: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canEdit($record): bool
|
public static function canEdit($record): bool
|
||||||
@ -24,20 +22,6 @@ class ApiKeyResource extends Resource
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTabs(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'all' => Tab::make('All Keys'),
|
|
||||||
'application' => Tab::make('Application Keys')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('key_type', ApiKey::TYPE_APPLICATION)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDefaultActiveTab(): string|int|null
|
|
||||||
{
|
|
||||||
return 'application';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getRelations(): array
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -25,24 +25,10 @@ class CreateApiKey extends CreateRecord
|
|||||||
->default(auth()->user()->id)
|
->default(auth()->user()->id)
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
Forms\Components\Select::make('key_type')
|
Forms\Components\Hidden::make('key_type')
|
||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->options(function (ApiKey $apiKey) {
|
->default(ApiKey::TYPE_APPLICATION)
|
||||||
$originalOptions = [
|
->required(),
|
||||||
//ApiKey::TYPE_NONE => 'None',
|
|
||||||
ApiKey::TYPE_ACCOUNT => 'Account',
|
|
||||||
ApiKey::TYPE_APPLICATION => 'Application',
|
|
||||||
//ApiKey::TYPE_DAEMON_USER => 'Daemon User',
|
|
||||||
//ApiKey::TYPE_DAEMON_APPLICATION => 'Daemon Application',
|
|
||||||
];
|
|
||||||
|
|
||||||
return collect($originalOptions)
|
|
||||||
->filter(fn ($value, $key) => $key <= ApiKey::TYPE_APPLICATION || $apiKey->key_type === $key)
|
|
||||||
->all();
|
|
||||||
})
|
|
||||||
->selectablePlaceholder(false)
|
|
||||||
->required()
|
|
||||||
->default(ApiKey::TYPE_APPLICATION),
|
|
||||||
|
|
||||||
Forms\Components\Fieldset::make('Permissions')
|
Forms\Components\Fieldset::make('Permissions')
|
||||||
->columns([
|
->columns([
|
||||||
|
@ -5,10 +5,8 @@ namespace App\Filament\Resources\ApiKeyResource\Pages;
|
|||||||
use App\Filament\Resources\ApiKeyResource;
|
use App\Filament\Resources\ApiKeyResource;
|
||||||
use App\Models\ApiKey;
|
use App\Models\ApiKey;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Resources\Components\Tab;
|
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
|
|
||||||
class ListApiKeys extends ListRecords
|
class ListApiKeys extends ListRecords
|
||||||
@ -19,12 +17,8 @@ class ListApiKeys extends ListRecords
|
|||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
->searchable(false)
|
->searchable(false)
|
||||||
|
->modifyQueryUsing(fn ($query) => $query->where('key_type', ApiKey::TYPE_APPLICATION))
|
||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('user.username')
|
|
||||||
->hidden()
|
|
||||||
->searchable()
|
|
||||||
->sortable(),
|
|
||||||
|
|
||||||
Tables\Columns\TextColumn::make('key')
|
Tables\Columns\TextColumn::make('key')
|
||||||
->copyable()
|
->copyable()
|
||||||
->icon('tabler-clipboard-text')
|
->icon('tabler-clipboard-text')
|
||||||
@ -41,6 +35,7 @@ class ListApiKeys extends ListRecords
|
|||||||
|
|
||||||
Tables\Columns\TextColumn::make('last_used_at')
|
Tables\Columns\TextColumn::make('last_used_at')
|
||||||
->label('Last Used')
|
->label('Last Used')
|
||||||
|
->placeholder('Not Used')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
@ -48,13 +43,13 @@ class ListApiKeys extends ListRecords
|
|||||||
->label('Created')
|
->label('Created')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
])
|
|
||||||
->filters([
|
Tables\Columns\TextColumn::make('user.username')
|
||||||
//
|
->label('Created By')
|
||||||
|
->url(fn (ApiKey $apiKey): string => route('filament.admin.resources.users.edit', ['record' => $apiKey->user])),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\DeleteAction::make(),
|
Tables\Actions\DeleteAction::make(),
|
||||||
//Tables\Actions\EditAction::make()
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,22 +59,4 @@ class ListApiKeys extends ListRecords
|
|||||||
Actions\CreateAction::make(),
|
Actions\CreateAction::make(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTabs(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'all' => Tab::make('All Keys'),
|
|
||||||
'application' => Tab::make('Application Keys')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('key_type', ApiKey::TYPE_APPLICATION)
|
|
||||||
),
|
|
||||||
'account' => Tab::make('Account Keys')
|
|
||||||
->modifyQueryUsing(fn (Builder $query) => $query->where('key_type', ApiKey::TYPE_ACCOUNT)
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDefaultActiveTab(): string|int|null
|
|
||||||
{
|
|
||||||
return 'application';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
|
|||||||
->schema([
|
->schema([
|
||||||
Grid::make('asdf')->columns(5)->schema([
|
Grid::make('asdf')->columns(5)->schema([
|
||||||
Section::make('Create API Key')->columnSpan(3)->schema([
|
Section::make('Create API Key')->columnSpan(3)->schema([
|
||||||
TextInput::make('description'),
|
TextInput::make('description')->required(),
|
||||||
TagsInput::make('allowed_ips')
|
TagsInput::make('allowed_ips')
|
||||||
->splitKeys([',', ' ', 'Tab'])
|
->splitKeys([',', ' ', 'Tab'])
|
||||||
->placeholder('Example: 127.0.0.1 or 192.168.1.1')
|
->placeholder('Example: 127.0.0.1 or 192.168.1.1')
|
||||||
@ -182,8 +182,9 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
|
|||||||
$action->success();
|
$action->success();
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
Section::make('API Keys')->columnSpan(2)->schema([
|
Section::make('Keys')->columnSpan(2)->schema([
|
||||||
Repeater::make('keys')
|
Repeater::make('keys')
|
||||||
|
->label('')
|
||||||
->relationship('apiKeys')
|
->relationship('apiKeys')
|
||||||
->addable(false)
|
->addable(false)
|
||||||
->itemLabel(fn ($state) => $state['identifier'])
|
->itemLabel(fn ($state) => $state['identifier'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user