From c68bb52609f6699b08acf627a6c45652f33c3b11 Mon Sep 17 00:00:00 2001 From: John Gaunt Date: Tue, 2 Nov 2021 14:17:41 -0400 Subject: [PATCH] added logic to add ldap user to sql table --- seafile-ldap.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/seafile-ldap.py b/seafile-ldap.py index f218798..bd021ee 100644 --- a/seafile-ldap.py +++ b/seafile-ldap.py @@ -192,7 +192,18 @@ for ldapUser in ldapUsers: else: logger.debug("LDAP User {0} is NOT in the SQL Table".format(ldapUser.mail)) # add user to ldap table - insert = '' + cnx = mysql.connector.connect(**dbconfig) + cursor = cnx.cursor() + query = "INSERT INTO LDAPUsers (email, is_staff, is_active) VALUES ({0}, {1}, {2})".format(ldapUser.mail, 0, 1) + logger.debug("Query: {0}".format(query)) + cursor.execute(query) + cnx.commit() + row_count = cursor.rowcount + if row_count == 1: + logger.debug("LDAP user {0} was added to the SQL Table".format(ldapUser.mail)) + else: + logger.error("Failed to add LDAP user {0} to the SQL Table".format(ldapUser.mail)) + cnx.close() #seafileUsers = request('admin/search-user/?query=@johnhgaunt.com', seafileURL, seafileToken)['response']['user_list']