From 0dedb545f0d7767d22bb2a028b0c48302ee8b07d Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 1 Aug 2022 19:05:12 +0100 Subject: [PATCH] Implement updating aliases --- api/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/views.py b/api/views.py index 754fd07..ba45d7a 100644 --- a/api/views.py +++ b/api/views.py @@ -381,3 +381,25 @@ class API(object): alias_list.append(alias_dup) return dumps({"aliases": alias_list}) + + @app.route("/aliases/", methods=["POST"]) + @login_required + def aliases_update(self, request): + try: + data = loads(request.content.read()) + except JSONDecodeError: + return "Invalid JSON" + for alias, fields in data.items(): + if not alias.isdigit(): + return dumps({"success": False, "reason": "alias not a number."}) + alias = int(alias) + if alias not in main.alias.keys(): + return dumps({"success": False, "reason": "alias does not exist."}) + if fields: + main.alias[alias] = fields + if "emails" in fields: + if not fields["emails"]: + main.alias[alias]["emails"] = [] + main.saveConf("alias") + + return dumps({"success": True})