Implement updating aliases
This commit is contained in:
parent
96d189290b
commit
b72d3d67a1
22
api/views.py
22
api/views.py
|
@ -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})
|
||||||
|
|
Loading…
Reference in New Issue