Beliebige Entra-Attribute ins Profil übernehmen; eigene Profilfelder
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m43s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m52s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m59s
CI / Build-Artefakte aktuell (pull_request) Successful in 57s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m43s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m52s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m59s
CI / Build-Artefakte aktuell (pull_request) Successful in 57s
- Profilfelder frei definierbar (Typ, Sichtbarkeit, selbst pflegbar), Werte als JSON am Benutzer - Attribut-Zuordnung je Anbieter statt fester Feldliste: jedes Graph-Attribut inkl. verschachtelter Pfade, onPremisesExtensionAttributes und Verzeichniserweiterungen - Erweiterungsattribute per Knopf aus Entra laden - $select dynamisch aus der Zuordnung; Delta-Abgleich startet bei geänderter Zuordnung neu - Rückfall auf Grundattribute, wenn einzelne Attribute nicht lesbar sind - Ältere Konfiguration (synced_fields) wird weiter gelesen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
51c94cd0cf
commit
6269d3302c
79 changed files with 1442 additions and 273 deletions
|
|
@ -7,21 +7,23 @@ use App\Filament\Resources\IdentityProviders\Pages\EditIdentityProvider;
|
|||
use App\Filament\Resources\IdentityProviders\Pages\ListIdentityProviders;
|
||||
use App\Filament\Resources\IdentityProviders\Pages\TestMapping;
|
||||
use App\Http\Controllers\Auth\IdentityLoginController;
|
||||
use App\Identity\Entra\EntraAttributes;
|
||||
use App\Identity\Entra\EntraDirectorySync;
|
||||
use App\Identity\Entra\MappingTester;
|
||||
use App\Models\IdentityProvider;
|
||||
use App\Models\IdpGroupMapping;
|
||||
use App\Models\Role;
|
||||
use App\Support\ProfileFields;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TagsInput;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Text;
|
||||
|
|
@ -107,11 +109,51 @@ class IdentityProviderResource extends Resource
|
|||
]),
|
||||
|
||||
Section::make('Profil')
|
||||
->description('Gewählte Felder kommen aus Entra ID und sind im Portal schreibgeschützt. Nicht gewählte pflegen die Personen selbst.')
|
||||
->key('profile')
|
||||
->description('Jedes Microsoft-Graph-Attribut lässt sich einem Profilfeld zuordnen – auch Personalnummer, Kostenstelle, lokale Erweiterungsattribute oder eigene Verzeichniserweiterungen. Zugeordnete Felder sind im Portal schreibgeschützt. Eigene Felder legen Sie unter „Profilfelder“ an.')
|
||||
->afterHeader([
|
||||
Action::make('loadExtensions')->label('Erweiterungsattribute laden')->icon(Heroicon::OutlinedArrowPath)
|
||||
->color('gray')->size('sm')
|
||||
->visible(fn (string $operation) => $operation === 'edit')
|
||||
->action(function (IdentityProvider $record) {
|
||||
try {
|
||||
$names = app(MappingTester::class)->loadExtensionProperties($record);
|
||||
Notification::make()->success()->title(count($names).' Verzeichniserweiterungen gefunden')
|
||||
->body($names === [] ? 'Im Mandanten sind keine Erweiterungen für Benutzer registriert.' : 'Sie stehen jetzt in der Attributauswahl zur Verfügung.')
|
||||
->send();
|
||||
} catch (Throwable $e) {
|
||||
Notification::make()->danger()->title('Erweiterungen konnten nicht geladen werden')
|
||||
->body($e->getMessage().' Benötigt die Anwendungsberechtigung Directory.Read.All.')->send();
|
||||
}
|
||||
}),
|
||||
])
|
||||
->schema([
|
||||
CheckboxList::make('config.synced_fields')->hiddenLabel()->columns(3)
|
||||
->options(IdentityProvider::SYNCABLE_FIELDS)
|
||||
->default(['first_name', 'last_name', 'email', 'job_title', 'department', 'location', 'phone', 'mobile', 'manager']),
|
||||
Repeater::make('config.attribute_map')
|
||||
->hiddenLabel()
|
||||
->columns(3)
|
||||
->addActionLabel('Zuordnung hinzufügen')
|
||||
->reorderable(false)
|
||||
->default(fn () => collect(EntraAttributes::DEFAULT_MAP)->map(fn ($attribute, $target) => ['target' => $target, 'attribute' => $attribute])->values()->all())
|
||||
->itemLabel(fn (array $state) => static::profileTargets()[$state['target'] ?? ''] ?? null)
|
||||
->collapsible(false)
|
||||
->schema([
|
||||
Select::make('target')->label('Profilfeld')->required()->native(false)
|
||||
->options(fn () => static::profileTargets())
|
||||
->disableOptionsWhenSelectedInSiblingRepeaterItems(),
|
||||
Select::make('suggestion')->label('Attribut auswählen')->placeholder('Aus der Liste übernehmen …')->searchable()->native(false)
|
||||
->options(fn (?IdentityProvider $record) => collect(EntraAttributes::suggestions($record))
|
||||
->mapWithKeys(fn ($label, $path) => [$path => $label.' · '.$path])->all())
|
||||
->live()
|
||||
->afterStateUpdated(fn (?string $state, Set $set) => $state ? $set('attribute', $state) : null)
|
||||
->dehydrated(false),
|
||||
TextInput::make('attribute')->label('Graph-Attribut')->required()->maxLength(191)
|
||||
->regex(EntraAttributes::PATH_PATTERN)
|
||||
->validationMessages(['regex' => 'Attributname oder Pfad mit Punkten, z. B. employeeOrgData.costCenter.'])
|
||||
->datalist(fn (?IdentityProvider $record) => array_keys(EntraAttributes::suggestions($record)))
|
||||
->placeholder('z. B. employeeId'),
|
||||
]),
|
||||
Text::make('Pfade mit Punkt lesen verschachtelte Werte (employeeOrgData.costCenter, businessPhones.0). Listen werden mit Komma verbunden. Manche Attribute brauchen zusätzliche Berechtigungen, z. B. employeeHireDate die Berechtigung User-LifeCycleInfo.Read.All.'),
|
||||
Toggle::make('config.sync_manager')->label('Vorgesetzte*n aus Entra übernehmen')->default(true),
|
||||
Toggle::make('config.sync_photo')->label('Profilfoto aus Entra übernehmen')->default(true),
|
||||
]),
|
||||
|
||||
|
|
@ -172,6 +214,15 @@ class IdentityProviderResource extends Resource
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> Zielfeld => Bezeichnung
|
||||
*/
|
||||
public static function profileTargets(): array
|
||||
{
|
||||
return IdentityProvider::PROFILE_TARGETS
|
||||
+ collect(app(ProfileFields::class)->options())->mapWithKeys(fn ($label, $key) => ['custom.'.$key => $label.' (Profilfeld)'])->all();
|
||||
}
|
||||
|
||||
public static function syncStatus(?IdentityProvider $record): HtmlString
|
||||
{
|
||||
if (! $record) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,13 @@ class EditIdentityProvider extends EditRecord
|
|||
{
|
||||
$data['config']['client_secret'] = null;
|
||||
|
||||
// Ältere Konfiguration (feste Feldliste) als Zuordnung anzeigen.
|
||||
if (! is_array($data['config']['attribute_map'] ?? null)) {
|
||||
$data['config']['attribute_map'] = collect($this->record->attributeMap())
|
||||
->map(fn ($attribute, $target) => ['target' => $target, 'attribute' => $attribute])->values()->all();
|
||||
$data['config']['sync_manager'] = $this->record->syncsManager();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +39,11 @@ class EditIdentityProvider extends EditRecord
|
|||
$data['config']['client_secret'] = $this->record->setting('client_secret');
|
||||
}
|
||||
|
||||
// Geladene Erweiterungen liegen nur in der Datenbank, nicht im Formular.
|
||||
$data['config']['extension_properties'] = $this->record->fresh()?->setting('extension_properties', []) ?? [];
|
||||
$data['config']['attribute_map'] = array_values((array) ($data['config']['attribute_map'] ?? []));
|
||||
unset($data['config']['synced_fields']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProfileFields\Pages;
|
||||
|
||||
use App\Filament\Resources\ProfileFields\ProfileFieldResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageProfileFields extends ManageRecords
|
||||
{
|
||||
protected static string $resource = ProfileFieldResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()->label('Profilfeld anlegen'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProfileFields;
|
||||
|
||||
use App\Filament\Resources\ProfileFields\Pages\ManageProfileFields;
|
||||
use App\Models\ProfileField;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Frei definierbare Profilfelder – etwa Personalnummer, Kostenstelle, Eintrittsdatum.
|
||||
* Können von den Personen selbst gepflegt oder aus Entra ID übernommen werden.
|
||||
*/
|
||||
class ProfileFieldResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProfileField::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedIdentification;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Benutzer & Rechte';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $modelLabel = 'Profilfeld';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Profilfelder';
|
||||
|
||||
protected static ?string $slug = 'profilfelder';
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('users.manage') ?? false;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('label')->label('Bezeichnung')->required()->maxLength(100),
|
||||
TextInput::make('key')->label('Technischer Schlüssel')
|
||||
->helperText('Wird aus der Bezeichnung erzeugt, wenn leer. Nachträglich nicht änderbar.')
|
||||
->regex('/^[a-z][a-z0-9_]*$/')
|
||||
->validationMessages(['regex' => 'Nur Kleinbuchstaben, Ziffern und Unterstriche, beginnend mit einem Buchstaben.'])
|
||||
->maxLength(60)
|
||||
->unique(ignoreRecord: true)
|
||||
->disabledOn('edit'),
|
||||
Select::make('type')->label('Typ')->options(ProfileField::TYPES)->default('text')->required()->native(false),
|
||||
Select::make('visibility')->label('Sichtbarkeit')->options(ProfileField::VISIBILITIES)->default('public')->required()->native(false),
|
||||
Toggle::make('editable')->label('Von der Person selbst pflegbar')->default(true)
|
||||
->helperText('Aus Entra ID übernommene Felder sind unabhängig davon schreibgeschützt.'),
|
||||
TextInput::make('sort')->label('Reihenfolge')->numeric()->default(0)->minValue(0),
|
||||
TextInput::make('help')->label('Hinweis im Profilformular')->maxLength(255)->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('sort')
|
||||
->reorderable('sort')
|
||||
->columns([
|
||||
TextColumn::make('label')->label('Bezeichnung')->weight('medium'),
|
||||
TextColumn::make('key')->label('Schlüssel')->fontFamily('mono')->color('gray'),
|
||||
TextColumn::make('type')->label('Typ')->formatStateUsing(fn (string $state) => ProfileField::TYPES[$state] ?? $state),
|
||||
TextColumn::make('visibility')->label('Sichtbarkeit')->badge()
|
||||
->formatStateUsing(fn (string $state) => $state === 'public' ? 'Alle' : 'Eingeschränkt')
|
||||
->color(fn (string $state) => $state === 'public' ? 'gray' : 'warning'),
|
||||
IconColumn::make('editable')->label('Selbst pflegbar')->boolean(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make()->modalDescription('Die gespeicherten Werte bleiben erhalten, werden aber nicht mehr angezeigt.'),
|
||||
])
|
||||
->emptyStateHeading('Noch keine Profilfelder')
|
||||
->emptyStateDescription('Zum Beispiel Personalnummer, Kostenstelle oder Eintrittsdatum – selbst gepflegt oder aus Entra ID übernommen.');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageProfileFields::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,16 @@
|
|||
|
||||
namespace App\Filament\Resources\Users\Schemas;
|
||||
|
||||
use App\Models\ProfileField;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Support\ProfileFields;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
|
@ -16,6 +20,30 @@ class UserForm
|
|||
{
|
||||
public const PHONE_REGEX = '/^[0-9+()\/\-.\s]{3,50}$/';
|
||||
|
||||
/**
|
||||
* Eingabefelder für die frei definierten Profilfelder.
|
||||
*
|
||||
* @return list<Component>
|
||||
*/
|
||||
private static function customFields(): array
|
||||
{
|
||||
return app(ProfileFields::class)->all()->map(function (ProfileField $field) {
|
||||
$name = 'custom_fields.'.$field->key;
|
||||
$hint = $field->visibility === 'restricted' ? 'Nur für die Person und die Personalverwaltung sichtbar.' : null;
|
||||
|
||||
$component = match ($field->type) {
|
||||
'textarea' => Textarea::make($name)->rows(3)->maxLength(5000)->columnSpanFull(),
|
||||
'date' => DatePicker::make($name)->native(false)->displayFormat('d.m.Y'),
|
||||
'email' => TextInput::make($name)->email()->maxLength(255),
|
||||
'url' => TextInput::make($name)->url()->maxLength(500),
|
||||
'phone' => TextInput::make($name)->tel()->telRegex(self::PHONE_REGEX)->maxLength(50),
|
||||
default => TextInput::make($name)->maxLength(255),
|
||||
};
|
||||
|
||||
return $component->label($field->label)->helperText($hint);
|
||||
})->values()->all();
|
||||
}
|
||||
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
|
|
@ -79,6 +107,11 @@ class UserForm
|
|||
->rule(Password::default())
|
||||
->dehydrated(fn (?string $state) => filled($state)),
|
||||
]),
|
||||
Section::make('Weitere Angaben')
|
||||
->columnSpan(2)
|
||||
->columns(2)
|
||||
->schema(fn () => self::customFields())
|
||||
->visible(fn () => app(ProfileFields::class)->all()->isNotEmpty()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue