Browse Source

Fix creation of users when there is no user in LDAP yet

Baptiste Jonglez 10 years ago
parent
commit
d4f6ee4ef9
2 changed files with 9 additions and 3 deletions
  1. 6 3
      coin/members/models.py
  2. 3 0
      coin/settings.py

+ 6 - 3
coin/members/models.py

@@ -180,13 +180,16 @@ class Member(CoinLdapSyncMixin, AbstractUser):
             ldap_user = LdapUser.objects.get(pk=self.username)
 
         if creation:
-            max_uid_number = LdapUser.objects.order_by(
-                '-uidNumber')[0].uidNumber
+            users = LdapUser.objects
+            if users.exists():
+                uid_number = users.order_by('-uidNumber')[0].uidNumber + 1
+            else:
+                uid_number = settings.LDAP_USER_FIRST_UID
             ldap_user = LdapUser()
             ldap_user.pk = self.username
             ldap_user.uid = self.username
             ldap_user.nick_name = self.username
-            ldap_user.uidNumber = max_uid_number + 1
+            ldap_user.uidNumber = uid_number
 
         ldap_user.last_name = self.last_name
         ldap_user.first_name = self.first_name

+ 3 - 0
coin/settings.py

@@ -234,6 +234,9 @@ LDAP_USER_BASE_DN = "ou=users,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
 LDAP_GROUP_BASE_DN = "ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
 VPN_CONF_BASE_DN = "ou=vpn,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
 
+# First UID to use for users
+LDAP_USER_FIRST_UID = 2000
+
 # Configuration for outgoing emails
 DEFAULT_FROM_EMAIL = "adminsys@illyse.org"
 #EMAIL_USE_TLS = True