Skip to content

Commit

Permalink
User: Fix Required User Defined Fields Block Login
Browse files Browse the repository at this point in the history
See: https://mantis.ilias.de/view.php?id=26628

This PR also reverts "Bugfix 28976 for R7"
 b8e78e7.
  • Loading branch information
kergomard committed Sep 5, 2023
1 parent f623437 commit 502d2c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
27 changes: 3 additions & 24 deletions Services/User/classes/class.ilCustomUserFieldsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 26 additions & 20 deletions Services/User/classes/class.ilCustomUserFieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +48,7 @@ public static function getInstance()
}
return self::$instance = new self();
}

/**
* Get udf types
* @return type
Expand All @@ -66,7 +66,7 @@ public function getUDFTypes()
}
return $types;
}

/**
* Get plugin for udf type
* @return ilUDFDefinitionPlugin
Expand All @@ -80,7 +80,7 @@ public function getPluginForType($a_type)
}
return null;
}

/**
* Get plugins for fields
* @param array $def_ids
Expand All @@ -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(
Expand All @@ -110,7 +110,7 @@ public function getActivePlugins()
}
return $plugins;
}

/**
* Get form property for definition
* @param array $definition
Expand All @@ -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) {
Expand All @@ -169,7 +175,7 @@ public function getFormPropertyForDefinition($definition, $a_changeable = true,
}
break;
}

return $fprop;
}
}
1 change: 0 additions & 1 deletion lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 502d2c4

Please sign in to comment.