fix(admin): insert mail into oc_mail_accounts
parent
02e1bcf331
commit
5527699e30
|
@ -1908,20 +1908,4 @@ class Admin:
|
|||
self.resync_data()
|
||||
|
||||
def set_nextcloud_user_mail(self, data):
|
||||
self.pg.update(
|
||||
"""INSERT INTO "oc_appconfig" ("user_id","name","email","inbound_host","inbound_port","inbound_ssl_mode","inbound_user","outbound_host","outbound_port","outbound_ssl_mode","outbound_user") VALUES
|
||||
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s),"""
|
||||
% (
|
||||
data["user_id"],
|
||||
data["name"],
|
||||
data["email"],
|
||||
data["inbound_host"],
|
||||
data["inbound_port"],
|
||||
data["inbound_ssl_mode"],
|
||||
data["inbound_user"],
|
||||
data["outbound_host"],
|
||||
data["outbound_port"],
|
||||
data["outbound_ssl_mode"],
|
||||
data["outbound_user"],
|
||||
)
|
||||
)
|
||||
self.nextcloud.set_user_mail(data)
|
||||
|
|
|
@ -518,3 +518,51 @@ class Nextcloud:
|
|||
# 101 - invalid input data
|
||||
# 102 - group already exists
|
||||
# 103 - failed to add the group
|
||||
|
||||
def set_user_mail(self, data):
|
||||
if not len(
|
||||
self.nextcloud_pg.select(
|
||||
"""SELECT * FROM "oc_mail_accounts" WHERE "email" = '%s'"""
|
||||
% (data["email"])
|
||||
)
|
||||
):
|
||||
self.nextcloud_pg.update(
|
||||
"""INSERT INTO "oc_mail_accounts" ("user_id","name","email","inbound_host","inbound_port","inbound_ssl_mode","inbound_user","inbound_password","outbound_host","outbound_port","outbound_ssl_mode","outbound_user","outbound_password") VALUES
|
||||
('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');"""
|
||||
% (
|
||||
data["user_id"],
|
||||
data["name"],
|
||||
data["email"],
|
||||
data["inbound_host"],
|
||||
data["inbound_port"],
|
||||
data["inbound_ssl_mode"],
|
||||
data["inbound_user"],
|
||||
data["inbound_password"],
|
||||
data["outbound_host"],
|
||||
data["outbound_port"],
|
||||
data["outbound_ssl_mode"],
|
||||
data["outbound_user"],
|
||||
data["outbound_password"],
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.nextcloud_pg.update(
|
||||
"""UPDATE "oc_mail_accounts" SET ("user_id","name","email","inbound_host","inbound_port","inbound_ssl_mode","inbound_user","inbound_password","outbound_host","outbound_port","outbound_ssl_mode","outbound_user","outbound_password") =
|
||||
('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') WHERE email = '%s';"""
|
||||
% (
|
||||
data["user_id"],
|
||||
data["name"],
|
||||
data["email"],
|
||||
data["inbound_host"],
|
||||
data["inbound_port"],
|
||||
data["inbound_ssl_mode"],
|
||||
data["inbound_user"],
|
||||
data["inbound_password"],
|
||||
data["outbound_host"],
|
||||
data["outbound_port"],
|
||||
data["outbound_ssl_mode"],
|
||||
data["outbound_user"],
|
||||
data["outbound_password"],
|
||||
data["email"],
|
||||
)
|
||||
)
|
||||
|
|
|
@ -268,7 +268,7 @@ def ddapi_group(id=None):
|
|||
|
||||
|
||||
@app.route("/ddapi/user_mail", methods=["POST"])
|
||||
@app.route("/ddapi/user_mail/<id>", methods=["GET", "POST", "DELETE"])
|
||||
@app.route("/ddapi/user_mail/<id>", methods=["GET", "DELETE"])
|
||||
@has_token
|
||||
def ddapi_user_mail(id=None):
|
||||
if request.method == "GET":
|
||||
|
@ -280,18 +280,26 @@ def ddapi_user_mail(id=None):
|
|||
if request.method == "POST":
|
||||
data = request.get_json(force=True)
|
||||
|
||||
if not app.validators["mails"].validate(data):
|
||||
raise Error(
|
||||
"bad_request",
|
||||
"Data validation for mail failed: "
|
||||
+ str(app.validators["mail"].errors),
|
||||
traceback.format_exc(),
|
||||
)
|
||||
# if not app.validators["mails"].validate(data):
|
||||
# raise Error(
|
||||
# "bad_request",
|
||||
# "Data validation for mail failed: "
|
||||
# + str(app.validators["mail"].errors),
|
||||
# traceback.format_exc(),
|
||||
# )
|
||||
for user in data:
|
||||
if not app.validators["mail"].validate(user):
|
||||
raise Error(
|
||||
"bad_request",
|
||||
"Data validation for mail failed: "
|
||||
+ str(app.validators["mail"].errors),
|
||||
traceback.format_exc(),
|
||||
)
|
||||
for user in data:
|
||||
log.info("Added user email")
|
||||
app.admin.set_nextcloud_user_mail(user)
|
||||
return (
|
||||
json.dumps("Not implemented yet"),
|
||||
json.dumps("Users emails updated"),
|
||||
200,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
|
|
|
@ -59,7 +59,7 @@ def socketio_connect():
|
|||
|
||||
@app.socketio.on("disconnect", namespace="/sio/events")
|
||||
def socketio_events_disconnect():
|
||||
None
|
||||
leave_room("events")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue