return mailbox in GET /api/v2/aliases

This commit is contained in:
Son NK 2020-04-25 23:13:05 +02:00
parent c8ed1437f1
commit 88ddca54c1
3 changed files with 40 additions and 17 deletions

View File

@ -852,6 +852,9 @@ If success, 200 with the list of aliases. Each alias has the following fields:
- nb_block
- nb_forward
- nb_reply
- mailbox
- id
- email
- (optional) latest_activity:
- action: forward|reply|block|bounced
- timestamp
@ -871,6 +874,10 @@ Here's an example:
"email": "prefix1.cat@sl.local",
"enabled": true,
"id": 3,
"mailbox": {
"email": "a@b.c",
"id": 1
},
"latest_activity": {
"action": "forward",
"contact": {
@ -891,6 +898,10 @@ Here's an example:
"email": "prefix0.hey@sl.local",
"enabled": true,
"id": 2,
"mailbox": {
"email": "a@b.c",
"id": 1
},
"latest_activity": {
"action": "forward",
"contact": {

View File

@ -51,6 +51,11 @@ def serialize_alias_info_v2(alias_info: AliasInfo) -> dict:
"nb_forward": alias_info.nb_forward,
"nb_block": alias_info.nb_blocked,
"nb_reply": alias_info.nb_reply,
# mailbox
"mailbox": {
"id": alias_info.mailbox.id,
"email": alias_info.mailbox.email
}
}
if alias_info.latest_email_log:
email_log = alias_info.latest_email_log

View File

@ -150,24 +150,28 @@ def test_get_aliases_v2(flask_client):
r0 = r.json["aliases"][0]
# r0 will have the following format
# {
# "creation_date": "2020-04-06 17:52:47+00:00",
# "creation_timestamp": 1586195567,
# "email": "prefix1.hey@sl.local",
# "enabled": true,
# "id": 3,
# "latest_activity": {
# "action": "forward",
# "contact": {
# "email": "c1@example.com",
# "name": null,
# "reverse_alias": "\"c1 at example.com\" <re1@SL>"
# "creation_date": "2020-04-25 21:10:01+00:00",
# "creation_timestamp": 1587849001,
# "email": "prefix1.yeah@sl.local",
# "enabled": true,
# "id": 3,
# "latest_activity": {
# "action": "forward",
# "contact": {
# "email": "c1@example.com",
# "name": null,
# "reverse_alias": "\"c1 at example.com\" <re1@SL>"
# },
# "timestamp": 1587849001
# },
# "timestamp": 1586195567
# },
# "nb_block": 0,
# "nb_forward": 1,
# "nb_reply": 0,
# "note": null
# "mailbox": {
# "email": "a@b.c",
# "id": 1
# },
# "nb_block": 0,
# "nb_forward": 1,
# "nb_reply": 0,
# "note": null
# }
assert r0["email"].startswith("prefix1")
assert r0["latest_activity"]["action"] == "forward"
@ -177,6 +181,9 @@ def test_get_aliases_v2(flask_client):
assert "name" in r0["latest_activity"]["contact"]
assert "reverse_alias" in r0["latest_activity"]["contact"]
assert "id" in r0["mailbox"]
assert "email" in r0["mailbox"]
def test_delete_alias(flask_client):
user = User.create(