Implement updating aliases

This commit is contained in:
Mark Veidemanis 2022-08-01 19:05:12 +01:00
parent 96d189290b
commit b72d3d67a1
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 22 additions and 0 deletions

View File

@ -381,3 +381,25 @@ class API(object):
alias_list.append(alias_dup) alias_list.append(alias_dup)
return dumps({"aliases": alias_list}) 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})