aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-05-13 15:23:59 +0200
committerMilo Casagrande <milo@ubuntu.com>2013-05-13 15:23:59 +0200
commitc90beb4934a29ea1f082e384040242823aa39404 (patch)
tree2628a1a401885f487295e9de13d7bef4df8e5cd7
parent7a4e78db466d6fd3259346281667f4dcf9aec34e (diff)
Fixed ldap sync script.
-rwxr-xr-xscripts/ldap-sync26
1 files changed, 16 insertions, 10 deletions
diff --git a/scripts/ldap-sync b/scripts/ldap-sync
index 9dcf3c5..272b0fc 100755
--- a/scripts/ldap-sync
+++ b/scripts/ldap-sync
@@ -398,7 +398,12 @@ class LdapSync():
if uid_or_cn[1] not in self.get_rhodecode_usernames():
# We can have more than one here, but we take the first.
- email = details.get('mail')[0]
+ try:
+ email = details.get('mail')[0]
+ except:
+ logger.warn("User %s has no 'mail' LDAP attribute." %
+ username)
+ email = 'Not provided'
try:
firstname = details.get('givenName')[0]
lastname = details.get('sn')[0]
@@ -532,13 +537,14 @@ if __name__ == '__main__':
sync.update_git_users_from_ldap(group, members)
# TODO
- # Commented out section, since right now there is not much stability on
- # LDAP side, and we receive different results. This would lead to false
- # users deactivation.
+ # We need a way to remove groups from RhodeCode that are not in LDAP anymore.
+ # At this time, RhodeCode API does not support group removal, it should be
+ # added in a future release.
+
# Users to remove.
- # diff = set(sync.get_rhodecode_usernames()).difference(set(all_usernames))
- # if diff:
- # for username in diff:
- # for group in groups:
- # sync.remove_user_from_group(username, group)
- # sync.disable_user(username)
+ diff = list(set(sync.get_rhodecode_usernames()).difference(set(all_usernames)))
+ if diff:
+ for username in diff:
+ for group in groups:
+ sync.remove_user_from_group(username, group)
+ sync.disable_user(username)