fix: [metafield limitation] fixes

- correctly show error messages on user creation when limits are hit
- fixed a bug that cause users from being uncreatable even due to a hit limitation, even if the current user wouldn't influence said limitation
develop
iglocska 2024-08-22 12:27:11 +02:00
parent 21d03ee585
commit ef2caed9c8
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 4 additions and 5 deletions

View File

@ -526,10 +526,10 @@ class CRUDComponent extends Component
if (!empty($errors)) {
if (count($errors) == 1) {
$field = array_keys($errors)[0];
$fieldError = implode(', ', array_values($errors[$field]));
$fieldError = json_encode($errors[$field]);
$validationMessage = __('{0}: {1}', $field, $fieldError);
} else {
$validationMessage = __('There has been validation issues with multiple fields');
$validationMessage = __('There has been validation issues with multiple fields: {0}', json_encode($errors));
}
}
return $validationMessage;

View File

@ -111,7 +111,6 @@ class UsersTable extends AppTable
}
}
}
if (!$enabled && !empty($entity->_metafields_to_delete)) {
foreach ($entity->_metafields_to_delete as $metaFieldToDelete) {
if ($metaFieldToDelete['field'] === $permission_name) {
@ -120,7 +119,7 @@ class UsersTable extends AppTable
}
}
if ($valueToCompareTo > $permission_data['limit']) {
if ($enabled && $valueToCompareTo > $permission_data['limit']) {
return [
$permission_name =>
__(
@ -202,7 +201,7 @@ class UsersTable extends AppTable
foreach ($permissionRestrictionCheck as $permission_name => $errors) {
foreach ($entity->meta_fields as $i => $metaField) {
if ($metaField['field'] === $permission_name) {
$entity->meta_fields[$i]->setErrors(['value' => $errors]);
$entity->setErrors(['meta_fields' => [$permission_name => $errors]]);
}
}
}