0001-ldap-allow-multivalued-attributes-in-user_attributes.patch
src/authentic2/backends/ldap_backend.py | ||
---|---|---|
64 | 64 |
from authentic2.a2_rbac.utils import get_default_ou |
65 | 65 |
from authentic2.ldap_utils import FilterFormatter |
66 | 66 |
from authentic2.utils import to_list |
67 |
from authentic2.custom_user.models import get_attributes_map |
|
67 | 68 | |
68 | 69 |
from authentic2.backends import is_user_authenticable |
69 | 70 | |
... | ... | |
780 | 781 |
if not from_ldap or not to_user: |
781 | 782 |
continue |
782 | 783 |
from_ldap = from_ldap.lower() |
783 |
if not attributes.get(from_ldap): |
|
784 |
user_attributes[to_user] = '' |
|
784 |
attribute_info = get_attributes_map().get(to_user) |
|
785 |
if not attribute_info: |
|
786 |
raise AttributeError(to_user) |
|
787 |
if attribute_info.multiple: |
|
788 |
user_attributes[to_user] = attributes.get(from_ldap, []) |
|
785 | 789 |
else: |
786 |
user_attributes[to_user] = attributes[from_ldap][0] |
|
790 |
if not attributes.get(from_ldap): |
|
791 |
user_attributes[to_user] = '' |
|
792 |
else: |
|
793 |
user_attributes[to_user] = attributes[from_ldap][0] |
|
787 | 794 |
for name in user_attributes: |
788 | 795 |
value = getattr(user.attributes, name, None) |
789 | 796 |
if value != user_attributes[name]: |
tests/test_ldap.py | ||
---|---|---|
870 | 870 |
'from_ldap': 'l', |
871 | 871 |
'to_user': 'locality', |
872 | 872 |
}, |
873 |
{ |
|
874 |
'from_ldap': 'o', |
|
875 |
'to_user': 'org', |
|
876 |
}, |
|
873 | 877 |
] |
874 | 878 |
}] |
875 | 879 | |
... | ... | |
884 | 888 |
asked_on_registration=False, |
885 | 889 |
multiple=False) |
886 | 890 | |
891 |
# create a org attribute |
|
892 |
models.Attribute.objects.create( |
|
893 |
label='org', |
|
894 |
name='org', |
|
895 |
kind='string', |
|
896 |
required=False, |
|
897 |
user_visible=True, |
|
898 |
user_editable=False, |
|
899 |
asked_on_registration=False, |
|
900 |
multiple=True) |
|
901 | ||
887 | 902 |
client.post('/login/', |
888 | 903 |
{ |
889 | 904 |
'login-password-submit': '1', |
... | ... | |
894 | 909 |
username = u'%s@ldap' % USERNAME |
895 | 910 |
user = User.objects.get(username=username) |
896 | 911 |
assert user.attributes.locality == u'Paris' |
912 |
assert sorted(user.attributes.org) == [u'EE', u'EO'] |
|
897 | 913 |
client.session.flush() |
898 | 914 |
for i in range(5): |
899 | 915 |
client.post('/login/', |
900 |
- |