From 9fc0748fcc5e27b71f663c1b9ecd804b29240255 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 3 Jun 2020 21:22:29 +0200 Subject: [PATCH] Support setting alias name in POST /api/v3/alias/custom/new --- README.md | 1 + app/api/views/new_custom_alias.py | 3 +++ tests/api/test_new_custom_alias.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 41d8cab3..efdb1bc1 100644 --- a/README.md +++ b/README.md @@ -835,6 +835,7 @@ Input: - signed_suffix: should be one of the suffixes returned in the `GET /api/v4/alias/options` endpoint. - mailbox_ids: list of mailbox_id that "owns" this alias - (Optional) note: alias note + - (Optional) name: alias name Output: If success, 201 with the new alias info. Use the same format as in GET /api/aliases/:alias_id diff --git a/app/api/views/new_custom_alias.py b/app/api/views/new_custom_alias.py index c79bc072..202e949d 100644 --- a/app/api/views/new_custom_alias.py +++ b/app/api/views/new_custom_alias.py @@ -204,6 +204,7 @@ def new_custom_alias_v3(): mailbox_ids: list of int optional "hostname" in args optional "note" + optional "name" Output: 201 if success @@ -231,6 +232,7 @@ def new_custom_alias_v3(): signed_suffix = data.get("signed_suffix", "").strip() mailbox_ids = data.get("mailbox_ids") note = data.get("note") + name = data.get("name") alias_prefix = convert_to_id(alias_prefix) # check if mailbox is not tempered with @@ -277,6 +279,7 @@ def new_custom_alias_v3(): user_id=user.id, email=full_alias, note=note, + name=name or None, mailbox_id=mailboxes[0].id, custom_domain_id=custom_domain_id, ) diff --git a/tests/api/test_new_custom_alias.py b/tests/api/test_new_custom_alias.py index e45622ea..ebd5df7b 100644 --- a/tests/api/test_new_custom_alias.py +++ b/tests/api/test_new_custom_alias.py @@ -211,6 +211,7 @@ def test_success_v3(flask_client): "signed_suffix": suffix, "note": "test note", "mailbox_ids": [user.default_mailbox_id, mb.id], + "name": "your name" }, ) @@ -228,6 +229,7 @@ def test_success_v3(flask_client): assert "nb_reply" in res assert "enabled" in res assert "note" in res + assert res["name"] == "your name" new_alias: Alias = Alias.get_by(email=r.json["alias"]) assert new_alias.note == "test note"