Add GET /api/mailboxes
This commit is contained in:
parent
88ddca54c1
commit
a422f33323
24
README.md
24
README.md
|
@ -831,6 +831,30 @@ Input:
|
||||||
|
|
||||||
Output: always return 200, even if email doesn't exist. User need to enter correctly their email.
|
Output: always return 200, even if email doesn't exist. User need to enter correctly their email.
|
||||||
|
|
||||||
|
#### GET /api/mailboxes
|
||||||
|
|
||||||
|
Get user verified mailboxes.
|
||||||
|
|
||||||
|
Input:
|
||||||
|
- `Authentication` header that contains the api key
|
||||||
|
|
||||||
|
Output:
|
||||||
|
List of mailboxes. Each mailbox has id, email field.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mailboxes": [
|
||||||
|
{
|
||||||
|
"email": "a@b.c",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "m1@example.com",
|
||||||
|
"id": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### GET /api/v2/aliases
|
#### GET /api/v2/aliases
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,7 @@ def serialize_alias_info_v2(alias_info: AliasInfo) -> dict:
|
||||||
"nb_block": alias_info.nb_blocked,
|
"nb_block": alias_info.nb_blocked,
|
||||||
"nb_reply": alias_info.nb_reply,
|
"nb_reply": alias_info.nb_reply,
|
||||||
# mailbox
|
# mailbox
|
||||||
"mailbox": {
|
"mailbox": {"id": alias_info.mailbox.id, "email": alias_info.mailbox.email},
|
||||||
"id": alias_info.mailbox.id,
|
|
||||||
"email": alias_info.mailbox.email
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if alias_info.latest_email_log:
|
if alias_info.latest_email_log:
|
||||||
email_log = alias_info.latest_email_log
|
email_log = alias_info.latest_email_log
|
||||||
|
|
|
@ -117,6 +117,27 @@ def get_aliases_v2():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_bp.route("/mailboxes", methods=["GET"])
|
||||||
|
@cross_origin()
|
||||||
|
@require_api_auth
|
||||||
|
def get_mailboxes():
|
||||||
|
"""
|
||||||
|
Get mailboxes
|
||||||
|
Output:
|
||||||
|
- mailboxes: list of alias:
|
||||||
|
- id
|
||||||
|
- email
|
||||||
|
"""
|
||||||
|
user = g.user
|
||||||
|
|
||||||
|
return (
|
||||||
|
jsonify(
|
||||||
|
mailboxes=[{"id": mb.id, "email": mb.email} for mb in user.mailboxes()]
|
||||||
|
),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@api_bp.route("/aliases/<int:alias_id>", methods=["DELETE"])
|
@api_bp.route("/aliases/<int:alias_id>", methods=["DELETE"])
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
@require_api_auth
|
@require_api_auth
|
||||||
|
|
|
@ -480,3 +480,28 @@ def test_get_alias(flask_client):
|
||||||
assert "nb_reply" in res
|
assert "nb_reply" in res
|
||||||
assert "enabled" in res
|
assert "enabled" in res
|
||||||
assert "note" in res
|
assert "note" in res
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_mailboxes(flask_client):
|
||||||
|
user = User.create(
|
||||||
|
email="a@b.c", password="password", name="Test User", activated=True
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# create api_key
|
||||||
|
api_key = ApiKey.create(user.id, "for test")
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
Mailbox.create(user_id=user.id, email="m1@example.com", verified=True)
|
||||||
|
Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
r = flask_client.get(
|
||||||
|
url_for("api.get_mailboxes"), headers={"Authentication": api_key.code},
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
# m2@example.com is not returned as it's not verified
|
||||||
|
assert r.json == {
|
||||||
|
"mailboxes": [{"email": "a@b.c", "id": 1}, {"email": "m1@example.com", "id": 2}]
|
||||||
|
}
|
||||||
|
print(json.dumps(r.json, indent=2))
|
||||||
|
|
Loading…
Reference in a new issue