diff --git a/composer.json b/composer.json index d64db52..e3fa4bc 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ "minimum-stability": "dev", "require": { "php": "^8.0", - "filament/filament": "^2.16", + "filament/filament": "^3.0", "lab404/laravel-impersonate": "^1.7", "spatie/laravel-package-tools": "^1.13", - "spatie/laravel-permission": "^5.5" + "spatie/laravel-permission": "^5.5|^6.0" }, "require-dev": { "laravel/pint": "^1.2" diff --git a/src/FilamentAuthenticationProvider.php b/src/FilamentAuthenticationProvider.php index f781f3e..b920615 100644 --- a/src/FilamentAuthenticationProvider.php +++ b/src/FilamentAuthenticationProvider.php @@ -4,14 +4,14 @@ use Filament\Facades\Filament; use Filament\Navigation\UserMenuItem; -use Filament\PluginServiceProvider; -use Filament\Tables\Columns\TextColumn; use Illuminate\Support\Facades\Config; -use Phpsa\FilamentAuthentication\Http\Middleware\ImpersonatingMiddleware; -use Phpsa\FilamentAuthentication\Widgets\LatestUsersWidget; +use Filament\Tables\Columns\TextColumn; use Spatie\LaravelPackageTools\Package; +use Spatie\LaravelPackageTools\PackageServiceProvider; +use Phpsa\FilamentAuthentication\Widgets\LatestUsersWidget; +use Phpsa\FilamentAuthentication\Http\Middleware\ImpersonatingMiddleware; -class FilamentAuthenticationProvider extends PluginServiceProvider +class FilamentAuthenticationProvider extends PackageServiceProvider { public static string $name = 'filament-authentication'; diff --git a/src/Pages/Profile.php b/src/Pages/Profile.php index 291bbee..5804021 100644 --- a/src/Pages/Profile.php +++ b/src/Pages/Profile.php @@ -30,7 +30,7 @@ class Profile extends Page */ public array $formData; - protected static function shouldRegisterNavigation(): bool + public static function shouldRegisterNavigation(): bool { return false; } @@ -52,7 +52,7 @@ public function mount(): void { $this->form->fill([ // @phpstan-ignore-next-line - 'name' => $this->getFormModel()->name, + 'name' => $this->getFormModel()->name, // @phpstan-ignore-next-line 'email' => $this->getFormModel()->email, ]); @@ -63,8 +63,8 @@ public function submit(): void $data = $this->form->getState(); $state = array_filter([ - 'name' => $data['name'], - 'email' => $data['email'], + 'name' => $data['name'], + 'email' => $data['email'], 'password' => $data['new_password'] ? Hash::make($data['new_password']) : null, ]); @@ -83,7 +83,7 @@ public function getCancelButtonUrlProperty(): string return static::getUrl(); } - protected function getBreadcrumbs(): array + public function getBreadcrumbs(): array { return [ url()->current() => 'Profile', diff --git a/src/Resources/PermissionResource.php b/src/Resources/PermissionResource.php index b9e5ddf..61e5d62 100644 --- a/src/Resources/PermissionResource.php +++ b/src/Resources/PermissionResource.php @@ -2,20 +2,24 @@ namespace Phpsa\FilamentAuthentication\Resources; -use Filament\Forms\Components\BelongsToManyMultiSelect; -use Filament\Forms\Components\Card; -use Filament\Forms\Components\Grid; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; +use Filament\Forms\Form; +use Filament\Tables\Table; use Filament\Resources\Resource; -use Filament\Resources\Table; +use Filament\Forms\Components\Grid; +use Filament\Tables\Actions\EditAction; +use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; -use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\CreatePermission; +use Filament\Forms\Components\TextInput; +use Spatie\Permission\Models\Permission; +use Filament\Tables\Actions\DeleteAction; +use Filament\Tables\Actions\DeleteBulkAction; +use Filament\Forms\Components\Section as Card; +use Filament\Forms\Components\BelongsToManyMultiSelect; use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\EditPermission; -use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\ListPermissions; use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\ViewPermission; +use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\ListPermissions; +use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\CreatePermission; use Phpsa\FilamentAuthentication\Resources\PermissionResource\RelationManager\RoleRelationManager; -use Spatie\Permission\Models\Permission; class PermissionResource extends Resource { @@ -33,7 +37,7 @@ public static function getLabel(): string return strval(__('filament-authentication::filament-authentication.section.permission')); } - protected static function getNavigationGroup(): ?string + public static function getNavigationGroup(): ?string { return strval(__(config('filament-authentication.section.group') ?? 'filament-authentication::filament-authentication.section.group')); } @@ -82,6 +86,14 @@ public static function table(Table $table): Table ]) ->filters([ // + ]) + ->actions([ + ViewAction::make(), + EditAction::make(), + DeleteAction::make(), + ]) + ->bulkActions([ + DeleteBulkAction::make(), ]); } @@ -95,10 +107,10 @@ public static function getRelations(): array public static function getPages(): array { return [ - 'index' => ListPermissions::route('/'), + 'index' => ListPermissions::route('/'), 'create' => CreatePermission::route('/create'), - 'edit' => EditPermission::route('/{record}/edit'), - 'view' => ViewPermission::route('/{record}'), + 'edit' => EditPermission::route('/{record}/edit'), + 'view' => ViewPermission::route('/{record}'), ]; } } diff --git a/src/Resources/PermissionResource/Pages/EditPermission.php b/src/Resources/PermissionResource/Pages/EditPermission.php index 7c4e4e1..6528428 100644 --- a/src/Resources/PermissionResource/Pages/EditPermission.php +++ b/src/Resources/PermissionResource/Pages/EditPermission.php @@ -2,10 +2,12 @@ namespace Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages; -use Filament\Resources\Pages\EditRecord; +use Filament\Actions\ViewAction; +use Filament\Actions\DeleteAction; use Illuminate\Support\Facades\Config; -use Spatie\Permission\Contracts\Permission; +use Filament\Resources\Pages\EditRecord; use Spatie\Permission\PermissionRegistrar; +use Spatie\Permission\Contracts\Permission; class EditPermission extends EditRecord { @@ -22,4 +24,12 @@ public function afterSave(): void app(PermissionRegistrar::class)->forgetCachedPermissions(); } + + protected function getHeaderActions(): array + { + return [ + ViewAction::make(), + DeleteAction::make(), + ]; + } } diff --git a/src/Resources/PermissionResource/Pages/ListPermissions.php b/src/Resources/PermissionResource/Pages/ListPermissions.php index 3d299c2..e884e96 100644 --- a/src/Resources/PermissionResource/Pages/ListPermissions.php +++ b/src/Resources/PermissionResource/Pages/ListPermissions.php @@ -2,11 +2,12 @@ namespace Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages; +use Filament\Actions\CreateAction; use Filament\Forms\Components\Select; -use Filament\Resources\Pages\ListRecords; +use Illuminate\Support\Facades\Config; use Filament\Tables\Actions\BulkAction; +use Filament\Resources\Pages\ListRecords; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Support\Facades\Config; class ListPermissions extends ListRecords { @@ -15,25 +16,32 @@ public static function getResource(): string return Config::get('filament-authentication.resources.PermissionResource'); } - protected function getTableBulkActions(): array + protected function getHeaderActions(): array { - $roleClass = config('filament-authentication.models.Role'); - return [ - BulkAction::make('Attach Role') - ->action(function (Collection $records, array $data): void { - // dd($data); - foreach ($records as $record) { - $record->roles()->sync($data['role']); - $record->save(); - } - }) - ->form([ - Select::make('role') - ->label(strval(__('filament-authentication::filament-authentication.field.role'))) - ->options((new $roleClass)::query()->pluck('name', 'id')) - ->required(), - ])->deselectRecordsAfterCompletion(), + CreateAction::make(), ]; } + + // protected function getTableBulkActions(): array + // { + // $roleClass = config('filament-authentication.models.Role'); + + // return [ + // BulkAction::make('Attach Role') + // ->action(function (Collection $records, array $data): void { + // // dd($data); + // foreach ($records as $record) { + // $record->roles()->sync($data['role']); + // $record->save(); + // } + // }) + // ->form([ + // Select::make('role') + // ->label(strval(__('filament-authentication::filament-authentication.field.role'))) + // ->options((new $roleClass())::query()->pluck('name', 'id')) + // ->required(), + // ])->deselectRecordsAfterCompletion(), + // ]; + // } } diff --git a/src/Resources/PermissionResource/Pages/ViewPermission.php b/src/Resources/PermissionResource/Pages/ViewPermission.php index 0f3dabf..10592d9 100644 --- a/src/Resources/PermissionResource/Pages/ViewPermission.php +++ b/src/Resources/PermissionResource/Pages/ViewPermission.php @@ -2,8 +2,9 @@ namespace Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages; -use Filament\Resources\Pages\ViewRecord; +use Filament\Actions\EditAction; use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\ViewRecord; class ViewPermission extends ViewRecord { @@ -11,4 +12,11 @@ public static function getResource(): string { return Config::get('filament-authentication.resources.PermissionResource'); } + + protected function getHeaderActions(): array + { + return[ + EditAction::make(), + ]; + } } diff --git a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php index d2d1e92..4e35041 100644 --- a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php +++ b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php @@ -2,20 +2,24 @@ namespace Phpsa\FilamentAuthentication\Resources\PermissionResource\RelationManager; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; -use Filament\Resources\RelationManagers\BelongsToManyRelationManager; -use Filament\Resources\Table; +use Filament\Forms\Form; +use Filament\Tables\Table; use Filament\Tables\Columns\TextColumn; +use Filament\Forms\Components\TextInput; +use Filament\Tables\Actions\AttachAction; +use Filament\Tables\Actions\CreateAction; +use Filament\Tables\Actions\DetachAction; use Spatie\Permission\PermissionRegistrar; +use Filament\Tables\Actions\DissociateBulkAction; +use Filament\Resources\RelationManagers\RelationManager; -class RoleRelationManager extends BelongsToManyRelationManager +class RoleRelationManager extends RelationManager { protected static string $relationship = 'roles'; protected static ?string $recordTitleAttribute = 'name'; - public static function form(Form $form): Form + public function form(Form $form): Form { return $form ->schema([ @@ -28,7 +32,7 @@ public static function form(Form $form): Form ]); } - public static function table(Table $table): Table + public function table(Table $table): Table { return $table ->columns([ @@ -38,8 +42,18 @@ public static function table(Table $table): Table ->label(strval(__('filament-authentication::filament-authentication.field.guard_name'))), ]) - ->filters([ - // + ->headerActions([ + CreateAction::make(), + AttachAction::make(), + ]) + ->actions([ + DetachAction::make() + ]) + + ->bulkActions([ + + DissociateBulkAction::make(), + ]); } @@ -52,4 +66,9 @@ public function afterDetach(): void { app(PermissionRegistrar::class)->forgetCachedPermissions(); } + + public function isReadOnly(): bool + { + return false; + } } diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index 9ea6713..57ad81d 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -2,21 +2,26 @@ namespace Phpsa\FilamentAuthentication\Resources; -use Filament\Forms\Components\BelongsToManyMultiSelect; -use Filament\Forms\Components\Card; -use Filament\Forms\Components\Grid; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; +use Filament\Forms\Form; +use Filament\Tables\Table; use Filament\Resources\Resource; -use Filament\Resources\Table; +use Spatie\Permission\Models\Role; +use Filament\Forms\Components\Grid; +use Filament\Tables\Actions\EditAction; +use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; -use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\CreateRole; +use Filament\Forms\Components\TextInput; +use Filament\Tables\Actions\DeleteAction; +use Filament\Tables\Filters\SelectFilter; +use Filament\Tables\Actions\DeleteBulkAction; +use Filament\Forms\Components\Section as Card; +use Filament\Forms\Components\BelongsToManyMultiSelect; use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\EditRole; -use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ListRoles; use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ViewRole; -use Phpsa\FilamentAuthentication\Resources\RoleResource\RelationManager\PermissionRelationManager; +use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ListRoles; +use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\CreateRole; use Phpsa\FilamentAuthentication\Resources\RoleResource\RelationManager\UserRelationManager; -use Spatie\Permission\Models\Role; +use Phpsa\FilamentAuthentication\Resources\RoleResource\RelationManager\PermissionRelationManager; class RoleResource extends Resource { @@ -34,7 +39,7 @@ public static function getLabel(): string return strval(__('filament-authentication::filament-authentication.section.role')); } - protected static function getNavigationGroup(): ?string + public static function getNavigationGroup(): ?string { return strval(__(config('filament-authentication.section.group') ?? 'filament-authentication::filament-authentication.section.group')); } @@ -84,7 +89,17 @@ public static function table(Table $table): Table ->searchable(), ]) ->filters([ - // + SelectFilter::make('guard_name') + ->multiple() + ->options(fn() => collect(config('auth.guards'))->keys()->mapWithKeys(fn($g) => [$g => $g])->toArray()) + ]) + ->actions([ + ViewAction::make(), + EditAction::make(), + DeleteAction::make(), + ]) + ->bulkActions([ + DeleteBulkAction::make(), ]); } @@ -99,10 +114,10 @@ public static function getRelations(): array public static function getPages(): array { return [ - 'index' => ListRoles::route('/'), + 'index' => ListRoles::route('/'), 'create' => CreateRole::route('/create'), - 'edit' => EditRole::route('/{record}/edit'), - 'view' => ViewRole::route('/{record}'), + 'edit' => EditRole::route('/{record}/edit'), + 'view' => ViewRole::route('/{record}'), ]; } } diff --git a/src/Resources/RoleResource/Pages/EditRole.php b/src/Resources/RoleResource/Pages/EditRole.php index 3a1f4ba..be32701 100644 --- a/src/Resources/RoleResource/Pages/EditRole.php +++ b/src/Resources/RoleResource/Pages/EditRole.php @@ -2,9 +2,11 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\Pages; -use Filament\Resources\Pages\EditRecord; -use Illuminate\Support\Facades\Config; +use Filament\Actions\ViewAction; +use Filament\Actions\DeleteAction; use Spatie\Permission\Contracts\Role; +use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\EditRecord; use Spatie\Permission\PermissionRegistrar; class EditRole extends EditRecord @@ -22,4 +24,12 @@ public function afterSave(): void app(PermissionRegistrar::class)->forgetCachedPermissions(); } + + protected function getHeaderActions(): array + { + return [ + ViewAction::make(), + DeleteAction::make(), + ]; + } } diff --git a/src/Resources/RoleResource/Pages/ListRoles.php b/src/Resources/RoleResource/Pages/ListRoles.php index 0ba27d1..1eb3e8b 100644 --- a/src/Resources/RoleResource/Pages/ListRoles.php +++ b/src/Resources/RoleResource/Pages/ListRoles.php @@ -2,8 +2,9 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\Pages; -use Filament\Resources\Pages\ListRecords; +use Filament\Actions\CreateAction; use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\ListRecords; class ListRoles extends ListRecords { @@ -11,4 +12,11 @@ public static function getResource(): string { return Config::get('filament-authentication.resources.RoleResource'); } + + protected function getHeaderActions(): array + { + return [ + CreateAction::make(), + ]; + } } diff --git a/src/Resources/RoleResource/Pages/ViewRole.php b/src/Resources/RoleResource/Pages/ViewRole.php index 0747c89..09411d2 100644 --- a/src/Resources/RoleResource/Pages/ViewRole.php +++ b/src/Resources/RoleResource/Pages/ViewRole.php @@ -2,8 +2,9 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\Pages; -use Filament\Resources\Pages\ViewRecord; +use Filament\Actions\EditAction; use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\ViewRecord; class ViewRole extends ViewRecord { @@ -11,4 +12,11 @@ public static function getResource(): string { return Config::get('filament-authentication.resources.RoleResource'); } + + protected function getHeaderActions(): array + { + return[ + EditAction::make(), + ]; + } } diff --git a/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php b/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php index c3c9699..3a3d1a6 100644 --- a/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php +++ b/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php @@ -2,33 +2,39 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\RelationManager; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; -use Filament\Resources\RelationManagers\BelongsToManyRelationManager; -use Filament\Resources\Table; +use Filament\Forms\Form; +use Filament\Tables\Table; use Filament\Tables\Columns\TextColumn; +use Filament\Forms\Components\TextInput; +use Filament\Tables\Actions\AttachAction; +use Filament\Tables\Actions\DetachAction; use Spatie\Permission\PermissionRegistrar; +use Filament\Tables\Actions\DissociateBulkAction; +use Filament\Resources\RelationManagers\RelationManager; +use Filament\Tables\Actions\CreateAction; -class PermissionRelationManager extends BelongsToManyRelationManager +class PermissionRelationManager extends RelationManager { protected static string $relationship = 'permissions'; protected static ?string $recordTitleAttribute = 'name'; - public static function form(Form $form): Form + public function form(Form $form): Form { return $form ->schema([ TextInput::make('name') + ->required() ->label(strval(__('filament-authentication::filament-authentication.field.name'))), TextInput::make('guard_name') + ->required() ->label(strval(__('filament-authentication::filament-authentication.field.guard_name'))) ->default(config('auth.defaults.guard')), ]); } - public static function table(Table $table): Table + public function table(Table $table): Table { return $table ->columns([ @@ -39,8 +45,18 @@ public static function table(Table $table): Table ->label(strval(__('filament-authentication::filament-authentication.field.guard_name'))), ]) - ->filters([ - // + ->headerActions([ + CreateAction::make(), + AttachAction::make(), + ]) + ->actions([ + DetachAction::make() + ]) + + ->bulkActions([ + + DissociateBulkAction::make(), + ]); } @@ -53,4 +69,10 @@ public function afterDetach(): void { app(PermissionRegistrar::class)->forgetCachedPermissions(); } + + + public function isReadOnly(): bool + { + return false; + } } diff --git a/src/Resources/RoleResource/RelationManager/UserRelationManager.php b/src/Resources/RoleResource/RelationManager/UserRelationManager.php index 48fbfca..499b039 100644 --- a/src/Resources/RoleResource/RelationManager/UserRelationManager.php +++ b/src/Resources/RoleResource/RelationManager/UserRelationManager.php @@ -2,17 +2,21 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\RelationManager; -use Filament\Resources\RelationManagers\BelongsToManyRelationManager; -use Filament\Resources\Table; +use Filament\Tables\Table; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Actions\AttachAction; +use Filament\Tables\Actions\DetachAction; +use Filament\Tables\Actions\BulkActionGroup; +use Filament\Tables\Actions\DissociateBulkAction; +use Filament\Resources\RelationManagers\RelationManager; -class UserRelationManager extends BelongsToManyRelationManager +class UserRelationManager extends RelationManager { protected static string $relationship = 'users'; protected static ?string $recordTitleAttribute = 'email'; - public static function table(Table $table): Table + public function table(Table $table): Table { return $table ->columns([ @@ -23,11 +27,25 @@ public static function table(Table $table): Table ->label(strval(__('filament-authentication::filament-authentication.field.name'))) ->searchable(), TextColumn::make('email') - ->label('Email'), + ->searchable() + ->label(strval(__('filament-authentication::filament-authentication.field.user.email'))), ]) ->filters([ // + ]) + ->headerActions([ + // ... + AttachAction::make(), + ]) + ->actions([ + DetachAction::make() + ]) + + ->bulkActions([ + + DissociateBulkAction::make(), + ]); } @@ -38,4 +56,9 @@ public function afterAttach(): void public function afterDetach(): void { } + + public function isReadOnly(): bool + { + return false; + } } diff --git a/src/Resources/UserResource.php b/src/Resources/UserResource.php index 9f47e52..896d06a 100644 --- a/src/Resources/UserResource.php +++ b/src/Resources/UserResource.php @@ -2,23 +2,26 @@ namespace Phpsa\FilamentAuthentication\Resources; - -use Filament\Forms\Components\Card; -use Filament\Forms\Components\Select; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; +use Filament\Forms\Form; +use Filament\Tables\Table; use Filament\Resources\Resource; -use Filament\Resources\Table; +use Illuminate\Support\Facades\Hash; +use Filament\Forms\Components\Select; +use Filament\Tables\Actions\EditAction; +use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TagsColumn; use Filament\Tables\Columns\TextColumn; +use Filament\Forms\Components\TextInput; +use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Filters\TernaryFilter; -use Illuminate\Support\Facades\Hash; +use Filament\Tables\Actions\DeleteBulkAction; +use Filament\Forms\Components\Section as Card; use Phpsa\FilamentAuthentication\Actions\ImpersonateLink; -use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\CreateUser; use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\EditUser; -use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\ListUsers; use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\ViewUser; +use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\ListUsers; +use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\CreateUser; class UserResource extends Resource { @@ -31,7 +34,7 @@ public function __construct() static::$model = config('filament-authentication.models.User'); } - protected static function getNavigationGroup(): ?string + public static function getNavigationGroup(): ?string { return strval(__(config('filament-authentication.section.group') ?? 'filament-authentication::filament-authentication.section.group')); } @@ -96,17 +99,12 @@ public static function table(Table $table): Table ->searchable() ->sortable() ->label(strval(__('filament-authentication::filament-authentication.field.user.email'))), + IconColumn::make('email_verified_at') - ->options([ - 'heroicon-o-check-circle', - 'heroicon-o-x-circle' => fn ($state): bool => $state === null, - ]) - ->colors([ - 'success', - 'danger' => fn ($state): bool => $state === null, - ]) + ->default(false) + ->boolean() ->label(strval(__('filament-authentication::filament-authentication.field.user.verified_at'))), - TagsColumn::make('roles.name') + TextColumn::make('roles.name')->badge() ->label(strval(__('filament-authentication::filament-authentication.field.user.roles'))), TextColumn::make('created_at') ->dateTime('Y-m-d H:i:s') @@ -117,8 +115,14 @@ public static function table(Table $table): Table ->label(strval(__('filament-authentication::filament-authentication.filter.verified'))) ->nullable(), ]) - ->prependActions([ + ->actions([ + ViewAction::make(), + EditAction::make(), + DeleteAction::make(), ImpersonateLink::make(), + ]) + ->bulkActions([ + DeleteBulkAction::make(), ]); } @@ -132,10 +136,10 @@ public static function getRelations(): array public static function getPages(): array { return [ - 'index' => ListUsers::route('/'), + 'index' => ListUsers::route('/'), 'create' => CreateUser::route('/create'), - 'edit' => EditUser::route('/{record}/edit'), - 'view' => ViewUser::route('/{record}'), + 'edit' => EditUser::route('/{record}/edit'), + 'view' => ViewUser::route('/{record}'), ]; } } diff --git a/src/Resources/UserResource/Pages/EditUser.php b/src/Resources/UserResource/Pages/EditUser.php index b387075..5d5e571 100644 --- a/src/Resources/UserResource/Pages/EditUser.php +++ b/src/Resources/UserResource/Pages/EditUser.php @@ -2,9 +2,11 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; -use Filament\Resources\Pages\EditRecord; -use Illuminate\Support\Facades\Config; +use Filament\Actions\DeleteAction; +use Filament\Actions\ViewAction; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\EditRecord; use Phpsa\FilamentAuthentication\Events\UserUpdated; class EditUser extends EditRecord @@ -27,4 +29,12 @@ protected function afterSave(): void { Event::dispatch(new UserUpdated($this->record)); } + + protected function getHeaderActions(): array + { + return [ + ViewAction::make(), + DeleteAction::make(), + ]; + } } diff --git a/src/Resources/UserResource/Pages/ListUsers.php b/src/Resources/UserResource/Pages/ListUsers.php index de01ea4..6e0d44e 100644 --- a/src/Resources/UserResource/Pages/ListUsers.php +++ b/src/Resources/UserResource/Pages/ListUsers.php @@ -2,8 +2,9 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; -use Filament\Resources\Pages\ListRecords; +use Filament\Actions\CreateAction; use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\ListRecords; class ListUsers extends ListRecords { @@ -11,4 +12,11 @@ public static function getResource(): string { return Config::get('filament-authentication.resources.UserResource'); } + + protected function getActions(): array + { + return [ + CreateAction::make(), + ]; + } } diff --git a/src/Resources/UserResource/Pages/ViewUser.php b/src/Resources/UserResource/Pages/ViewUser.php index 2e4f6b2..4704bf7 100644 --- a/src/Resources/UserResource/Pages/ViewUser.php +++ b/src/Resources/UserResource/Pages/ViewUser.php @@ -3,7 +3,8 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; use Filament\Facades\Filament; -use Filament\Pages\Actions\Action; +use Filament\Actions\Action; +use Filament\Actions\EditAction; use Filament\Resources\Pages\ViewRecord; use Illuminate\Support\Facades\Config; use Illuminate\Validation\UnauthorizedException; @@ -16,23 +17,25 @@ public static function getResource(): string return Config::get('filament-authentication.resources.UserResource'); } - protected function getActions(): array + protected function getHeaderActions(): array { - $user = Filament::auth()->user(); - if ($user === null) { - throw new UnauthorizedException(); - } + return collect([ + EditAction::make(), + $this->impersonateAction(), + ])->filter()->toArray(); + } - if (ImpersonateLink::allowed($user, $this->record)) { - return array_merge([ - Action::make('impersonate') - ->button() - ->action(function () { - ImpersonateLink::impersonate($this->record); - }), - ], parent::getActions()); + protected function impersonateAction(): ?Action + { + /** @var \Illuminate\Contracts\Auth\Authenticatable */ + $record = $this->getRecord(); + $user = Filament::auth()->user(); + if ($user === null || ImpersonateLink::allowed($user, $record) === false) { + throw null; } - return parent::getActions(); + return Action::make('impersonate') + ->label(__('filament-authentication::filament-authentication.button.impersonate')) + ->action(fn() => ImpersonateLink::impersonate($record)); } } diff --git a/src/Resources/UserResource/RelationManager/RoleRelationManager.php b/src/Resources/UserResource/RelationManager/RoleRelationManager.php index 8f2b662..49375fe 100644 --- a/src/Resources/UserResource/RelationManager/RoleRelationManager.php +++ b/src/Resources/UserResource/RelationManager/RoleRelationManager.php @@ -3,19 +3,19 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\RelationManager; use Filament\Forms\Components\TextInput; -use Filament\Resources\Form; -use Filament\Resources\RelationManagers\BelongsToManyRelationManager; -use Filament\Resources\Table; +use Filament\Forms\Form; +use Filament\Resources\RelationManagers\RelationManager; +use Filament\Tables\Table; use Filament\Tables\Columns\TextColumn; use Spatie\Permission\PermissionRegistrar; -class RoleRelationManager extends BelongsToManyRelationManager +class RoleRelationManager extends RelationManager { protected static string $relationship = 'roles'; protected static ?string $recordTitleAttribute = 'name'; - public static function form(Form $form): Form + public function form(Form $form): Form { return $form ->schema([ @@ -28,7 +28,7 @@ public static function form(Form $form): Form ]); } - public static function table(Table $table): Table + public function table(Table $table): Table { return $table ->columns([