Fixing Z-Push sync errors

This commit is contained in:
Andrés Ortiz 2017-01-27 09:51:42 -06:00
parent a3c71fe14f
commit 789b5ce485
1 changed files with 18 additions and 1 deletions

View File

@ -288,8 +288,9 @@ def add_mail_user(email, pw, privs, env):
validation = validate_privilege(p)
if validation: return validation
# get the database
# get the system database and OwnCloud database
conn, c = open_database(env, with_connection=True)
conn_oc, c_oc = open_database(env, with_connection=True, db_path="/owncloud/owncloud.db")
# hash the password
pw = hash_password(pw)
@ -304,6 +305,15 @@ def add_mail_user(email, pw, privs, env):
# write databasebefore next step
conn.commit()
#fix sync cardDav error on Exchange connections, adding the user into OwnCloud DB
try:
c_oc.execute("INSERT INTO oc_users_external (backend, uid) VALUES (?, ?)",
("{127.0.0.1:993/imap/ssl/novalidate-cert}", email))
except sqlite3.IntegrityError:
return ("User already exists on calendar/contact server.", 400)
conn_oc.commit()
# Update things in case any new domains are added.
return kick(env, "mail user added")
@ -348,6 +358,13 @@ def remove_mail_user(email, env):
return ("That's not a user (%s)." % email, 400)
conn.commit()
#delete user from OwnCloud DB too
conn_oc, c_oc = open_database(env, with_connection=True, db_path="/owncloud/owncloud.db")
c_oc.execute("DELETE FROM oc_users_external WHERE email=?", (email,))
if c.rowcount != 1:
return ("This email (%s) wasn't in contacts/calendar server.", % email, 400)
conn_oc.commit()
# Update things in case any domains are removed.
return kick(env, "mail user removed")