From 502d2c4cc4613a7db2a7f2356a25b6c2464a2181 Mon Sep 17 00:00:00 2001 From: Stephan Kergomard Date: Tue, 5 Sep 2023 09:16:05 +0200 Subject: [PATCH] User: Fix Required User Defined Fields Block Login See: https://mantis.ilias.de/view.php?id=26628 This PR also reverts "Bugfix 28976 for R7" b8e78e7c81977755e4521540f5d4512b210ae6d7. --- .../classes/class.ilCustomUserFieldsGUI.php | 27 ++--------- .../class.ilCustomUserFieldsHelper.php | 46 +++++++++++-------- lang/ilias_de.lang | 1 - lang/ilias_en.lang | 1 - 4 files changed, 29 insertions(+), 46 deletions(-) diff --git a/Services/User/classes/class.ilCustomUserFieldsGUI.php b/Services/User/classes/class.ilCustomUserFieldsGUI.php index 0ccfa2388590..b97de5b0a5d6 100644 --- a/Services/User/classes/class.ilCustomUserFieldsGUI.php +++ b/Services/User/classes/class.ilCustomUserFieldsGUI.php @@ -383,12 +383,6 @@ protected function validateForm($form, $user_field_definitions, array &$access, $valid = false; } - if ($access['required'] && $access['visible'] && !$access['changeable']) { - $this->confirm_change = true; - $form->getItemByPostVar("access")->setAlert($lng->txt('udf_required_and_visible_requires_changeable')); - $valid = false; - } - if (!$this->field_id && $user_field_definitions->nameExists($form->getInput("name"))) { $form->getItemByPostVar("name")->setAlert($lng->txt('udf_name_already_exists')); $valid = false; @@ -710,31 +704,16 @@ public function updateFields($action = "") } } } - - $valid = true; - + foreach ($a_fields as $field_id => $definition) { if (isset($_POST['chb']['required_' . $field_id]) && (int) $_POST['chb']['required_' . $field_id] && (!isset($_POST['chb']['visib_reg_' . $field_id]) || !(int) $_POST['chb']['visib_reg_' . $field_id])) { $this->confirm_change = true; ilUtil::sendFailure($lng->txt('invalid_visible_required_options_selected')); - $valid = false; + $this->listUserDefinedFields(); + return false; } - - if (isset($_POST['chb']['required_' . $field_id]) && (int) $_POST['chb']['required_' . $field_id] && - isset($_POST['chb']['visible_' . $field_id]) && (int) $_POST['chb']['visible_' . $field_id] && - (!isset($_POST['chb']['changeable_' . $field_id]) || !(int) $_POST['chb']['changeable_' . $field_id])) { - $this->confirm_change = true; - - ilUtil::sendFailure($lng->txt('udf_required_and_visible_requires_changeable')); - $valid = false; - } - } - - if (!$valid) { - $this->listUserDefinedFields(); - return false; } foreach ($a_fields as $field_id => $definition) { diff --git a/Services/User/classes/class.ilCustomUserFieldsHelper.php b/Services/User/classes/class.ilCustomUserFieldsHelper.php index 0fad215e42fb..c825b69b1103 100644 --- a/Services/User/classes/class.ilCustomUserFieldsHelper.php +++ b/Services/User/classes/class.ilCustomUserFieldsHelper.php @@ -17,26 +17,26 @@ class ilCustomUserFieldsHelper * @var ilLanguage */ private $lng = null; - + /** * @var ilPluginAdmin */ private $plugin_admin = null; - + /** * @var ilLogger */ private $logger = null; - + public function __construct() { global $DIC; - + $this->lng = $DIC->language(); $this->logger = $DIC->logger()->usr(); $this->plugin_admin = $DIC['ilPluginAdmin']; } - + /** * Get instance * @return ilCustomUserFieldsHelper @@ -48,7 +48,7 @@ public static function getInstance() } return self::$instance = new self(); } - + /** * Get udf types * @return type @@ -66,7 +66,7 @@ public function getUDFTypes() } return $types; } - + /** * Get plugin for udf type * @return ilUDFDefinitionPlugin @@ -80,7 +80,7 @@ public function getPluginForType($a_type) } return null; } - + /** * Get plugins for fields * @param array $def_ids @@ -89,7 +89,7 @@ public function getPluginForType($a_type) public function getActivePlugins() { $plugins = array(); - + include_once './Services/User/classes/class.ilUDFDefinitionPlugin.php'; foreach ( $this->plugin_admin->getActivePluginsForSlot( @@ -110,7 +110,7 @@ public function getActivePlugins() } return $plugins; } - + /** * Get form property for definition * @param array $definition @@ -119,46 +119,52 @@ public function getActivePlugins() public function getFormPropertyForDefinition($definition, $a_changeable = true, $a_default_value = null) { $fprop = null; - + switch ($definition['field_type']) { case UDF_TYPE_TEXT: $fprop = new ilTextInputGUI( $definition['field_name'], 'udf_' . $definition['field_id'] ); - $fprop->setDisabled(!$a_changeable); $fprop->setValue($a_default_value); $fprop->setSize(40); $fprop->setMaxLength(255); $fprop->setRequired($definition['required'] ? true : false); + if (!$a_changeable && (!$definition['required'] || $a_default_value)) { + $fprop->setDisabled(true); + } break; - + case UDF_TYPE_WYSIWYG: $fprop = new ilTextAreaInputGUI( $definition['field_name'], 'udf_' . $definition['field_id'] ); - $fprop->setDisabled(!$a_changeable); $fprop->setValue($a_default_value); $fprop->setUseRte(true); $fprop->setRequired($definition['required'] ? true : false); + if (!$a_changeable && (!$definition['required'] || $a_default_value)) { + $fprop->setDisabled(true); + } break; - + case UDF_TYPE_SELECT: $fprop = new ilSelectInputGUI( $definition['field_name'], 'udf_' . $definition['field_id'] ); - $fprop->setDisabled(!$a_changeable); - + include_once './Services/User/classes/class.ilUserDefinedFields.php'; $user_defined_fields = ilUserDefinedFields::_getInstance(); - + $fprop->setOptions($user_defined_fields->fieldValuesToSelectArray($definition['field_values'])); $fprop->setValue($a_default_value); $fprop->setRequired($definition['required'] ? true : false); + if (!$a_changeable && (!$definition['required'] || $a_default_value)) { + $fprop->setDisabled(true); + } break; - + default: // should be a plugin foreach ($this->getActivePlugins() as $plugin) { @@ -169,7 +175,7 @@ public function getFormPropertyForDefinition($definition, $a_changeable = true, } break; } - + return $fprop; } } diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 10b0b696f53d..836d99dd1729 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -5740,7 +5740,6 @@ common#:#udf_delete_sure#:#Sind Sie sicher, dass Sie diese Feld und alle zugehö common#:#udf_duplicate_entries#:#Die Werte müssen eindeutig sein. common#:#udf_field_deleted#:#Das Feld wurde gelöscht. common#:#udf_name_already_exists#:#Ein Feld mit diesem Namen existiert bereits. Bitte wählen Sie einen anderen Feldnamen. -common#:#udf_required_and_visible_requires_changeable#:#Wenn die Einstellungen "Erforderliche Angabe" und "Sichtbar in den persönlichen Daten" aktiviert sind, muss auch "Kann durch Benutzer selbst im Profil geändert werden" aktiviert sein common#:#udf_required_requires_visib_reg#:#Die Einstellung "Erforderliche Angabe" erfordert die Einstellung "Sichtbar im Registrierungsformular" common#:#udf_type_date#:#Datum common#:#udf_type_datetime#:#Datum und Uhrzeit diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 430de46afb9a..15de84424f51 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -5741,7 +5741,6 @@ common#:#udf_delete_sure#:#Are you sure you want to delete this field and all as common#:#udf_duplicate_entries#:#The values have to be unique. common#:#udf_field_deleted#:#Deleted field. common#:#udf_name_already_exists#:#This field name already exists. Please choose a different name. -common#:#udf_required_and_visible_requires_changeable#:#When a field is ‘Required’ and ‘Visible in Personal Data’, it must also be ‘Changeable in Profile’ common#:#udf_required_requires_visib_reg#:#When a field is ‘Required’, it must also be ‘Visible in Registration’ common#:#udf_type_date#:#Date common#:#udf_type_datetime#:#Date and Time