import univention.admin import univention.admin.modules import univention.admin.hook import univention.admin.handlers.users.user import univention.testing.utils def mydebug(msg): univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, '40_extended_attribute_attributehook_value_mapping: MySampleHook: %s' % (msg,)) mydebug('TEST MODULE LOADED') class MySampleHook(univention.admin.hook.AttributeHook): ldap_attribute_name = 'univentionFreeAttribute3' udm_attribute_name = 'myTestUDMProperty' def map_attribute_value_to_ldap(self, value): mydebug('map_attribute_value_to_ldap(%r)' % (value,)) if value == 'FALSE': return 'no' elif value == 'TRUE': return 'yes' elif value in ('', None): return '' else: # this is not great, but works reasonably well mydebug('map_attribute_value_to_ldap(%r) ==> found invalid value' % (value,)) raise univention.admin.uexceptions.valueError('%s: Value may not be %r' % (self.ldap_attribute_name, value)) def map_attribute_value_to_udm(self, value): mydebug('map_attribute_value_to_udm(%r)' % (value,)) if value == 'yes': return 'TRUE' elif value == 'no': return 'FALSE' elif value in ('', None): return '' else: # this is not great, but works reasonably well mydebug('map_attribute_value_to_udm(%r) ==> found invalid value' % (value,)) raise univention.admin.uexceptions.valueError('%s: Value may not be %r' % (self.udm_attribute_name, value))