Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
4.0 KiB
PHP
100 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Users\Schemas;
|
|
|
|
use App\Enums\AdminMode;
|
|
use App\Enums\UserRole;
|
|
use App\Models\User;
|
|
use App\Tenancy\TenantContext;
|
|
use Closure;
|
|
use Filament\Forms\Components\Radio;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Schemas\Schema;
|
|
|
|
class UserForm
|
|
{
|
|
public static function configure(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->columns(2)
|
|
->components([
|
|
TextInput::make('name')
|
|
->label('Name')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('email')
|
|
->label('E-Mail (Anmeldename)')
|
|
->helperText('Besteht die E-Mail schon, kommt das Konto zu diesem Mandanten dazu. Passwort und Zwei-Faktor-Anmeldung bleiben.')
|
|
->email()
|
|
->required()
|
|
->maxLength(255)
|
|
->rules([
|
|
fn (?User $record): Closure => function (string $attribute, mixed $value, Closure $fail) use ($record): void {
|
|
if (! is_string($value)) {
|
|
return;
|
|
}
|
|
|
|
$existing = User::query()->where('email', $value)->first();
|
|
|
|
if ($existing === null) {
|
|
return;
|
|
}
|
|
|
|
if ($record !== null) {
|
|
if ($existing->isNot($record)) {
|
|
$fail('Diese E-Mail wird schon verwendet.');
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
$tenantId = app(TenantContext::class)->id();
|
|
|
|
if ($tenantId !== null && $existing->tenants()->where('tenants.id', $tenantId)->exists()) {
|
|
$fail('Diese Person gehört schon zu diesem Mandanten.');
|
|
}
|
|
},
|
|
]),
|
|
Radio::make('role')
|
|
->label('Rolle')
|
|
->helperText('Gilt für diesen Mandanten.')
|
|
->options(UserRole::class)
|
|
->required()
|
|
->afterStateHydrated(function (Radio $component, ?User $record): void {
|
|
if ($record === null) {
|
|
return;
|
|
}
|
|
|
|
$tenantId = app(TenantContext::class)->id();
|
|
$role = $tenantId !== null ? ($record->roleOn($tenantId) ?? $record->role) : $record->role;
|
|
|
|
if ($role !== null) {
|
|
$component->state($role->value);
|
|
}
|
|
})
|
|
->columnSpanFull(),
|
|
Radio::make('admin_mode')
|
|
->label('Ansicht')
|
|
->helperText('Bestimmt nur, was im Menü erscheint. Leer = Administratoren Expertenansicht, alle anderen einfache Ansicht. Jederzeit umschaltbar über das Benutzermenü oben rechts.')
|
|
->options(AdminMode::class)
|
|
->columnSpanFull(),
|
|
TextInput::make('password')
|
|
->label(fn (string $operation): string => $operation === 'create' ? 'Passwort' : 'Neues Passwort (leer lassen = unverändert)')
|
|
->password()
|
|
->revealable()
|
|
->minLength(10)
|
|
->required(fn (string $operation): bool => $operation === 'create')
|
|
->visible(function (string $operation, ?User $record): bool {
|
|
if ($operation === 'create') {
|
|
return true;
|
|
}
|
|
|
|
$actor = auth()->user();
|
|
|
|
return $actor instanceof User && $actor->mayResetCredentials($record);
|
|
})
|
|
->dehydrated(fn (?string $state): bool => filled($state)),
|
|
]);
|
|
}
|
|
}
|