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

- 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:
Friederich Loheide 2026-09-26 08:09:57 +00:00
parent 51c94cd0cf
commit 6269d3302c
79 changed files with 1442 additions and 273 deletions

View file

@ -9,6 +9,8 @@ use App\Models\UserIdentity;
use App\Support\Audit;
use App\Support\Avatars;
use App\Support\Permissions\Permissions;
use App\Support\ProfileFields;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
@ -20,7 +22,10 @@ use Throwable;
*/
class IdentitySync
{
public function __construct(private readonly Avatars $avatars) {}
public function __construct(
private readonly Avatars $avatars,
private readonly ProfileFields $profileFields,
) {}
/**
* Konto zu einer externen Identität finden, verknüpfen oder anlegen.
@ -113,11 +118,56 @@ class IdentitySync
: null;
}
$custom = $this->customFieldChanges($user, $fields, (array) ($profile['custom'] ?? []));
if ($custom !== null) {
$changes['custom_fields'] = $custom;
}
if ($changes !== []) {
$user->forceFill($changes)->save();
}
}
/**
* Freie Profilfelder aus dem Anbieter übernehmen. Datumswerte werden als
* Y-m-d gespeichert, Werte ohne Felddefinition ignoriert.
*
* @param list<string> $fields
* @param array<string, string|null> $incoming
* @return array<string, string>|null null = keine Änderung
*/
private function customFieldChanges(User $user, array $fields, array $incoming): ?array
{
$definitions = $this->profileFields->all()->keyBy('key');
$values = (array) ($user->custom_fields ?? []);
$before = $values;
foreach ($incoming as $key => $value) {
$field = $definitions->get($key);
if (! $field || ! in_array('custom.'.$key, $fields, true)) {
continue;
}
if ($value !== null && $field->type === 'date') {
try {
$value = Carbon::parse($value)->format('Y-m-d');
} catch (Throwable) {
// Unlesbares Datum: unverändert übernehmen.
}
}
if ($value === null) {
unset($values[$key]);
} else {
$values[$key] = $value;
}
}
return $values === $before ? null : $values;
}
/**
* Profilfoto übernehmen, wenn es sich geändert hat. null = kein Foto beim Anbieter.
*/