[horde] question on horde identities on_change hook

Jan Schneider jan at horde.org
Wed Mar 29 13:59:20 UTC 2017


Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:

> Quoting Jan Schneider <jan at horde.org>:
>
>> Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:
>>
>>> Quoting Jan Schneider <jan at horde.org>:
>>>
>>>> Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:
>>>>
>>>>> Quoting Jan Schneider <jan at horde.org>:
>>>>>
>>>>>> Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I try to write an on_change hook for horde  
>>>>>>> identities/from_addr. My goal is to restrict the
>>>>>>> addresses our users can configure in horde/imp to their own  
>>>>>>> addresses and variants (plus-addressing).
>>>>>>> The address verification feature  
>>>>>>> ($conf[user][verify_from_addr]) could work but we don't want to
>>>>>>> allow external addresses and it should be unnecessary to send  
>>>>>>> an email as we already know the
>>>>>>> allowed addresses.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> In horde/config/prefs.local.php I have the following function.
>>>>>>>
>>>>>>> $_prefs['from_addr']['on_change'] = function() {
>>>>>>> global $prefs, $registry;
>>>>>>> $data = $GLOBALS['registry']->getAuthInfo();
>>>>>>> $userID=$data['authId'];
>>>>>>> $value=$GLOBALS['prefs']->getValue('identities');
>>>>>>> $value2=$prefs->getValue('from_addr');
>>>>>>> Horde::logMessage("Horde Prefs call on_change for identities:  
>>>>>>> ".$userID." value: ".$value." value2: ".$value2);
>>>>>>> myVerifyFunction($userID, $value);
>>>>>>> }
>>>>>>>
>>>>>>> This function is call every time the Identity UI/form is saved.
>>>>>>> But the value retrieved by getValue('identities') still  
>>>>>>> contain the old value before the change.
>>>>>>> This is different then the other on_change calls in horde/imp  
>>>>>>> prefs.php (e.g. language, use_trash, trash_folder)
>>>>>>> how can I retrieve the new value.
>>>>>>
>>>>>> This is because the from_addr preference, as being a part of  
>>>>>> the identities preference, won't really get stored. You need to  
>>>>>> use on_change hook for the identities preference instead.
>>>>>
>>>>> I tried that before, but if i use  
>>>>> $_prefs['identities']['on_change'] = function() { ....
>>>>> the hook is not called at all. I guess that is because  
>>>>> 'identities' is a prefGroup?
>>>>
>>>> It's both, but on_change is only set on prefs. Without looking at  
>>>> the code, just to the description of on_change in prefs.php, it  
>>>> seems to be tied to changing prefs through the *UI*. That would  
>>>> explain why it isn't called on 'identities' that's updated  
>>>> implicitely. And it would also explain why you cannot update the
>>>> identites pref inside this callback: it's updated *after* the  
>>>> form submission and thus also after the on_change callback.
>>>>
>>>
>>> Should i open a bug ticket?
>>
>> No, it's not a bug.
>
> really? either the on_change hook for form_addr should be called  
> after the identities pref
> is stored or the on_change hook should be called for for identities.  
> The later could be called
> a missing feature combined with the missing documentation that  
> on_change is not called for
> identities.

If reading the description carefully, it behaves exactly as advertised:

"A method to call when this prefs value is changed in the UI."

-- 
Jan Schneider
The Horde Project
https://www.horde.org/



More information about the horde mailing list