update ldap loop for seafile api variable and
This commit is contained in:
@@ -150,6 +150,11 @@ for user in ldapUsers:
|
||||
cnx = mysql.connector.connect(**dbconfig)
|
||||
cursor = cnx.cursor()
|
||||
# Starting query for sql ldap users
|
||||
seafileUsers = request('admin/search-user/?query=@{0}'.format(adminEmail.split("@")[1]), seafileURL, seafileToken)['response']['user_list']
|
||||
for seafileUser in seafileUsers:
|
||||
if seafileUser['email'] == adminEmail
|
||||
continue
|
||||
|
||||
logger.debug("Starting SQL query for LDAPUsers")
|
||||
query = ("SELECT * FROM LDAPUsers")
|
||||
logger.debug("Query: {0}".format(query))
|
||||
@@ -173,9 +178,9 @@ for ldapUser in ldapUsers:
|
||||
if seafileUser['email'] == ldapUser.mail:
|
||||
# User is in the sql table
|
||||
# are they active
|
||||
is_active = bool(sqlLDAPuser[0][4])
|
||||
is_active = bool(seafileUser['is_active'])
|
||||
# log the results
|
||||
logger.debug("LDAP User {0} is already in the SQL Table, Is Active: {1}".format(ldapUser.mail, is_active))
|
||||
logger.debug("LDAP User {0} is already in Seafile, Is Active: {1}".format(ldapUser.mail, is_active))
|
||||
# if user is not active, they should be
|
||||
if not is_active:
|
||||
logger.info("User {0} is NOT active in Seafile".format(ldapUser.mail))
|
||||
@@ -187,7 +192,7 @@ for ldapUser in ldapUsers:
|
||||
logger.error("There was an error setting user {0} to active in Seafile".format(ldapUser.mail))
|
||||
# user is not in the SQL table
|
||||
else:
|
||||
logger.info("LDAP User {0} is NOT in the SQL Table".format(ldapUser.mail))
|
||||
logger.info("LDAP User {0} is NOT in Seafile".format(ldapUser.mail))
|
||||
# add user to ldap table
|
||||
cnx = mysql.connector.connect(**dbconfig)
|
||||
cursor = cnx.cursor()
|
||||
@@ -197,9 +202,9 @@ for ldapUser in ldapUsers:
|
||||
cnx.commit()
|
||||
row_count = cursor.rowcount
|
||||
if row_count == 1:
|
||||
logger.info("LDAP user {0} was added to the SQL Table".format(ldapUser.mail))
|
||||
logger.info("LDAP user {0} was added to the Seafile SQL Table".format(ldapUser.mail))
|
||||
else:
|
||||
logger.error("Failed to add LDAP user {0} to the SQL Table".format(ldapUser.mail))
|
||||
logger.error("Failed to add LDAP user {0} to the Seafile SQL Table".format(ldapUser.mail))
|
||||
cnx.close()
|
||||
# Update seafile user profile with new name
|
||||
updateSeafileUserName = request('admin/users/{0}/'.format(ldapUser.mail), seafileURL, seafileToken, "PUT", {"name": "{0}".format(ldapUser.displayName)})
|
||||
|
||||
Reference in New Issue
Block a user