User adjustments

This commit is contained in:
Lance Pioch 2024-03-31 02:09:23 -04:00
parent 1728cbf28b
commit 2b172e6d8b
2 changed files with 28 additions and 10 deletions

View File

@ -27,13 +27,16 @@ class UserResource extends Resource
->schema([
Forms\Components\TextInput::make('username')->required()->maxLength(191),
Forms\Components\TextInput::make('email')->email()->required()->maxLength(191),
Forms\Components\TextInput::make('name_first')->maxLength(191),
Forms\Components\TextInput::make('name_last')->maxLength(191),
Forms\Components\TextInput::make('name_first')->maxLength(191)->label('First Name'),
Forms\Components\TextInput::make('name_last')->maxLength(191)->label('Last Name'),
Forms\Components\TextInput::make('password')->password()->columnSpanFull(),
Forms\Components\Hidden::make('skipValidation')->default(true),
Forms\Components\Select::make('language')->required()->default('en')
->options(fn (User $user) => $user->getAvailableLanguages()),
Forms\Components\Toggle::make('root_admin')->required()->default(0)
->disabled(fn () => User::where('root_admin', true)->count() <= 1),
Forms\Components\Toggle::make('root_admin')
->required()
->default(false),
// ->disabled(fn () => User::where('root_admin', true)->count() <= 1),
]);
}
@ -52,11 +55,18 @@ class UserResource extends Resource
->searchable(),
Tables\Columns\TextColumn::make('username')
->searchable(),
Tables\Columns\TextColumn::make('email')->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable()
->icon('tabler-mail'),
Tables\Columns\TextColumn::make('name')
->hidden()
->searchable(),
Tables\Columns\IconColumn::make('root_admin')->label('Admin')->boolean()->sortable(),
Tables\Columns\IconColumn::make('root_admin')
->label('Admin')
->boolean()
->trueIcon('tabler-adjustments-check')
->falseIcon('tabler-adjustments-cancel')
->sortable(),
Tables\Columns\IconColumn::make('use_totp')->label('2FA')
->icon(fn (User $user) => $user->use_totp ? 'tabler-lock' : 'tabler-lock-open-off')
->boolean()->sortable(),

View File

@ -7,7 +7,7 @@ use App\Rules\Username;
use App\Facades\Activity;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\In;
use Illuminate\Auth\Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -141,18 +141,20 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
'language' => 'en',
'use_totp' => false,
'totp_secret' => null,
'name_first' => '',
'name_last' => '',
];
/**
* Rules verifying that the data being stored matches the expectations of the database.
*/
public static array $validationRules = [
'uuid' => 'required|string|size:36|unique:users,uuid',
'uuid' => 'nullable|string|size:36|unique:users,uuid',
'email' => 'required|email|between:1,191|unique:users,email',
'external_id' => 'sometimes|nullable|string|max:191|unique:users,external_id',
'username' => 'required|between:1,191|unique:users,username',
'name_first' => 'required|string|between:1,191',
'name_last' => 'required|string|between:1,191',
'name_first' => 'nullable|string|between:0,191',
'name_last' => 'nullable|string|between:0,191',
'password' => 'sometimes|nullable|string',
'root_admin' => 'boolean',
'language' => 'string',
@ -172,6 +174,12 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
protected static function booted(): void
{
static::creating(function (self $user) {
$user->uuid = Str::uuid();
return true;
});
static::deleting(function (self $user) {
throw_if($user->servers()->count() > 0, new DisplayException(__('admin/user.exceptions.user_has_servers')));