Commit 7af41ff1 authored by Côme Chilliet's avatar Côme Chilliet

feat(hooks) Make special password attrs available to hooks on any user tab

issue #5977
parent 3b51520d
...@@ -1422,6 +1422,16 @@ class simplePlugin implements SimpleTab ...@@ -1422,6 +1422,16 @@ class simplePlugin implements SimpleTab
return $this->handle_hooks('PRE', $mode, $addAttrs); return $this->handle_hooks('PRE', $mode, $addAttrs);
} }
function fillHookAttrs (array &$addAttrs)
{
// Walk trough attributes list and add the plugins attributes.
foreach ($this->attributes as $attr) {
if (!isset($addAttrs[$attr])) {
$addAttrs[$attr] = $this->$attr;
}
}
}
/*! /*!
* \brief Calls external hooks which are defined for this plugin (fusiondirectory.conf) * \brief Calls external hooks which are defined for this plugin (fusiondirectory.conf)
* Replaces placeholder by class values of this plugin instance. * Replaces placeholder by class values of this plugin instance.
...@@ -1438,10 +1448,7 @@ class simplePlugin implements SimpleTab ...@@ -1438,10 +1448,7 @@ class simplePlugin implements SimpleTab
$messages = []; $messages = [];
foreach ($commands as $command) { foreach ($commands as $command) {
// Walk trough attributes list and add the plugins attributes. $this->fillHookAttrs($addAttrs);
foreach ($this->attributes as $attr) {
$addAttrs[$attr] = $this->$attr;
}
$ui = get_userinfo(); $ui = get_userinfo();
...@@ -1455,11 +1462,9 @@ class simplePlugin implements SimpleTab ...@@ -1455,11 +1462,9 @@ class simplePlugin implements SimpleTab
$addAttrs['location'] = $config->current['NAME']; $addAttrs['location'] = $config->current['NAME'];
if (isset($this->parent->by_object)) { if (isset($this->parent->by_object)) {
foreach ($this->parent->by_object as $object) { foreach ($this->parent->by_object as $class => $object) {
foreach ($object->attributes as $attr) { if ($class != get_class($this)) {
if (!isset($addAttrs[$attr])) { $object->fillHookAttrs($addAttrs);
$addAttrs[$attr] = $object->$attr;
}
} }
} }
} }
......
...@@ -142,4 +142,11 @@ interface SimpleTab ...@@ -142,4 +142,11 @@ interface SimpleTab
* Used by prepare_save and template::apply * Used by prepare_save and template::apply
*/ */
public function mergeObjectClasses (array $oc): array; public function mergeObjectClasses (array $oc): array;
/*!
* \brief Fill attributes which may be used in hooks
*
* Used by simplePlugin::callHook
*/
public function fillHookAttrs (array &$addAttrs);
} }
...@@ -389,12 +389,12 @@ class user extends simplePlugin ...@@ -389,12 +389,12 @@ class user extends simplePlugin
} }
} }
function callHook ($cmd, array $addAttrs = [], &$returnOutput = [], &$returnCode = NULL): array function fillHookAttrs (array &$addAttrs)
{ {
parent::fillHookAttrs($addAttrs);
$addAttrs['passwordMethod'] = $this->attributesAccess['userPassword']->getMethod(); $addAttrs['passwordMethod'] = $this->attributesAccess['userPassword']->getMethod();
$addAttrs['userLocked'] = (int)($this->attributesAccess['userPassword']->isLocked()); $addAttrs['userLocked'] = (int)($this->attributesAccess['userPassword']->isLocked());
$addAttrs['passwordClear'] = $this->attributesAccess['userPassword']->getClear(); $addAttrs['passwordClear'] = $this->attributesAccess['userPassword']->getClear();
return parent::callHook($cmd, $addAttrs, $returnOutput, $returnCode);
} }
static function reportPasswordProblems ($user, $new_password, $repeated_password, $current_password = NULL) static function reportPasswordProblems ($user, $new_password, $repeated_password, $current_password = NULL)
......
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