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})