Commit e9490320 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5886-support-disabling-specific-password-methods' into '1.4-dev'

Resolve "Support disabling specific password methods"

See merge request fusiondirectory/fd!609
parents 13653866 96e2d60b
......@@ -99,6 +99,14 @@ class CompositeAttribute extends Attribute
$this->linearRendering = $bool;
}
function loadValue (array $attrs)
{
parent::loadValue($attrs);
foreach ($this->attributes as $attribute) {
$attribute->setInitialValue($attribute->getValue());
}
}
function readValues (string $value): array
{
$res = preg_match($this->readFormat, $value, $m);
......
......@@ -157,20 +157,28 @@ class SelectAttribute extends Attribute
function renderFormInput (): string
{
$smarty = get_smarty();
$id = $this->getHtmlId();
$smarty->assign($id."_choices", $this->choices);
$smarty = get_smarty();
$id = $this->getHtmlId();
$smartyChoices = $this->choices;
$currentValue = $this->getValue();
if ($this->outputs !== NULL) {
$smartyOutputs = array_values($this->outputs);
} else {
$smartyOutputs = $this->choices;
}
if (!in_array($currentValue, $smartyChoices)) {
$smartyChoices[] = $currentValue;
$smartyOutputs[] = $currentValue;
}
$key = array_search('', $smartyOutputs, TRUE);
if ($key !== FALSE) {
$smartyOutputs[$key] = ' ';
}
$smarty->assign($id."_outputs", $smartyOutputs);
$smarty->assign($id."_selected", $this->getValue());
$smarty->assign($id.'_choices', $smartyChoices);
$smarty->assign($id.'_outputs', $smartyOutputs);
$smarty->assign($id.'_selected', $currentValue);
$display = '<select name="'.$id.'" id="'.$id.'" ';
if ($this->disabled || (count($this->choices) == 0)) {
$display .= 'disabled="disabled" ';
......
......@@ -112,6 +112,14 @@ class UserPasswordAttribute extends CompositeAttribute
}
}
function loadValue (array $attrs)
{
parent::loadValue($attrs);
/* Needs to reset previousMethodInfo to force check, because initialValue of attribute 0 changed */
$this->previousMethodInfo = NULL;
$this->checkIfMethodNeedsPassword();
}
/*! \brief Loads this attribute value from the attrs array
*/
protected function loadAttrValue (array $attrs)
......@@ -122,7 +130,6 @@ class UserPasswordAttribute extends CompositeAttribute
$this->setValue($this->inputValue(''));
} else {
$this->attributes[0]->resetToDefault();
$this->checkIfMethodNeedsPassword();
}
}
......@@ -152,11 +159,11 @@ class UserPasswordAttribute extends CompositeAttribute
$methodInfo = $method.$this->attributes[3]->getValue();
if ($methodInfo != $this->previousMethodInfo) {
if (isset($this->needPassword[$method]) && $this->needPassword[$method]) {
$hashEmpty = ($this->attributes[3]->getValue() == '');
$hashEmptyOrMethodChange = (($this->attributes[3]->getValue() == '') || $this->attributes[0]->hasChanged());
$this->attributes[1]->setVisible(TRUE);
$this->attributes[1]->setRequired($hashEmpty);
$this->attributes[1]->setRequired($hashEmptyOrMethodChange);
$this->attributes[2]->setVisible(TRUE);
$this->attributes[2]->setRequired($hashEmpty);
$this->attributes[2]->setRequired($hashEmptyOrMethodChange);
} else {
$this->attributes[1]->setRequired(FALSE);
$this->attributes[1]->setVisible(FALSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment