mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #181 from YunoHost/LDAP_validate_uniqueness
Add possiblity to get attribute name of conflict in LDAP
This commit is contained in:
commit
9a8b5c080a
1 changed files with 24 additions and 7 deletions
|
@ -234,13 +234,30 @@ class Authenticator(BaseAuthenticator):
|
||||||
Boolean | MoulinetteError
|
Boolean | MoulinetteError
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for attr, value in value_dict.items():
|
attr_found = self.get_conflict(value_dict)
|
||||||
if not self.search(filter=attr + '=' + value):
|
if attr_found:
|
||||||
continue
|
|
||||||
else:
|
|
||||||
logger.info("attribute '%s' with value '%s' is not unique",
|
logger.info("attribute '%s' with value '%s' is not unique",
|
||||||
attr, value)
|
attr_found[0], attr_found[1])
|
||||||
raise MoulinetteError(errno.EEXIST,
|
raise MoulinetteError(errno.EEXIST,
|
||||||
m18n.g('ldap_attribute_already_exists',
|
m18n.g('ldap_attribute_already_exists',
|
||||||
attribute=attr, value=value))
|
attribute=attr_found[0],
|
||||||
|
value=attr_found[1]))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_conflict(self, value_dict, base_dn=None):
|
||||||
|
"""
|
||||||
|
Check uniqueness of values
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
value_dict -- Dictionnary of attributes/values to check
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None | list with Fist conflict attribute name and value
|
||||||
|
|
||||||
|
"""
|
||||||
|
for attr, value in value_dict.items():
|
||||||
|
if not self.search(base=base_dn, filter=attr + '=' + value):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return (attr, value)
|
||||||
|
return None
|
||||||
|
|
Loading…
Add table
Reference in a new issue