fix: name missing fields the user cannot edit on personal data page

This commit is contained in:
fromme committed 2026-10-16 17:46:05 +02:00
1 parent 6d2db1b258
commit 0ee8fafbe1
8 files changed
+187 -12

No files matched your search

+33 -4
View File
@@ -11,13 +11,22 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
* Validates profile completeness for booking requirements.
*
* Checks whether a user's personal data contains all required fields needed to create
* or edit bookings using Symfony's validation system with the 'personal_data' group.
* or edit bookings using Symfony's validation system with the 'personal_data' and
* 'personal_identity' groups.
* Required fields include name, gender, date of birth, nationality, contact information,
* and full address data.
*/
class ProfileCompletenessChecker
{
private const VALIDATION_GROUP = 'personal_data';
private const VALIDATION_GROUPS = ['personal_data', 'personal_identity'];
private const IDENTITY_GROUP = 'personal_identity';
// Fields in personal_identity, which the user cannot edit in MyE&P, by violation property path.
private const IDENTITY_FIELD_LABELS = [
'firstName' => 'Vorname',
'name' => 'Nachname',
'communication.email' => 'E-Mail-Adresse',
];
public function __construct(
private readonly ValidatorInterface $validator,
@@ -27,7 +36,7 @@ class ProfileCompletenessChecker
/**
* Checks if the personal data contains all required fields for booking operations.
*
* Validates against the 'personal_data' group which includes:
* Validates against the 'personal_data' and 'personal_identity' groups, which include:
* - firstName and name (personal identification)
* - gender and dateOfBirth (personal attributes)
* - nationality (booking form requirement)
@@ -40,8 +49,28 @@ class ProfileCompletenessChecker
*/
public function isComplete(PersonalData $personalData): bool
{
$violations = $this->validator->validate($personalData, null, [self::VALIDATION_GROUP]);
$violations = $this->validator->validate($personalData, null, self::VALIDATION_GROUPS);
return 0 === $violations->count();
}
/**
* Lists the missing or invalid fields the user cannot fix themselves, because only customer
* service may change them in BusPro.
*
* @return list<string> Field labels, in the order of IDENTITY_FIELD_LABELS
*/
public function invalidIdentityFields(PersonalData $personalData): array
{
$paths = [];
foreach ($this->validator->validate($personalData, null, [self::IDENTITY_GROUP]) as $violation) {
$paths[$violation->getPropertyPath()] = true;
}
return array_values(array_filter(
self::IDENTITY_FIELD_LABELS,
static fn (string $path): bool => isset($paths[$path]),
\ARRAY_FILTER_USE_KEY,
));
}
}