Permalink
Browse files

changed behavior of django_user_set method such that it returns an em…

…pty queryset when a group has no members instead of raising an exception specific to LDAP.
  • Loading branch information...
1 parent 5578b21 commit b44c75e9f3ca1ea7f1297b08889877cef1ded9fe John Huddleston committed Jul 27, 2010
Showing with 11 additions and 6 deletions.
  1. +11 −6 utils.py
View
@@ -22,6 +22,7 @@ def get_users_by_distinguished_name(distinguished_names):
Takes a list of LDAP distinguished names (DNs) and returns a Django User
queryset for all of those group members.
"""
+ # TODO: create Django instances for members who don't have one.
members = map(get_common_name, distinguished_names)
full_names = set([m for m in members if len(m.split(" ")) == 2])
user_names = set(members).difference(full_names)
@@ -57,10 +58,14 @@ def django_user_set_for_ldap_group(group):
Django Group model instance. Found: %s\
""" % type(group))
- return get_users_by_distinguished_name(
- LDAP("wwu").search_groups(
- group_name,
- ["member"]
- )[0].member
- )
+ group = LDAP("wwu").search_groups(
+ group_name,
+ ["member"]
+ )[0]
+
+ # Attribute "member" won't exist if there are no users in the group.
+ if hasattr(group, "member"):
+ return get_users_by_distinguished_name(group.member)
+ else:
+ return User.objects.none()

0 comments on commit b44c75e

Please sign in to comment.