GET /api/aliases/:alias_id
This commit is contained in:
parent
78b24623af
commit
159aa76aae
25
README.md
25
README.md
|
@ -861,6 +861,31 @@ If success, 200 with the list of aliases, for example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### GET /api/aliases/:alias_id
|
||||||
|
|
||||||
|
Get alias info
|
||||||
|
|
||||||
|
Input:
|
||||||
|
- `Authentication` header that contains the api key
|
||||||
|
- `alias_id` in url
|
||||||
|
|
||||||
|
Output:
|
||||||
|
Alias info
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"creation_date": "2020-02-04 16:23:02+00:00",
|
||||||
|
"creation_timestamp": 1580833382,
|
||||||
|
"email": "e3@.alo@sl.local",
|
||||||
|
"id": 4,
|
||||||
|
"nb_block": 0,
|
||||||
|
"nb_forward": 0,
|
||||||
|
"nb_reply": 0,
|
||||||
|
"enabled": true,
|
||||||
|
"note": "This is a note"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### DELETE /api/aliases/:alias_id
|
#### DELETE /api/aliases/:alias_id
|
||||||
|
|
||||||
Delete an alias
|
Delete an alias
|
||||||
|
|
|
@ -12,6 +12,7 @@ from app.dashboard.views.alias_log import get_alias_log
|
||||||
from app.dashboard.views.index import (
|
from app.dashboard.views.index import (
|
||||||
AliasInfo,
|
AliasInfo,
|
||||||
get_alias_infos_with_pagination,
|
get_alias_infos_with_pagination,
|
||||||
|
get_alias_info,
|
||||||
)
|
)
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
|
@ -210,6 +211,27 @@ def update_alias(alias_id):
|
||||||
return jsonify(note=new_note), 200
|
return jsonify(note=new_note), 200
|
||||||
|
|
||||||
|
|
||||||
|
@api_bp.route("/aliases/<int:alias_id>", methods=["GET"])
|
||||||
|
@cross_origin()
|
||||||
|
@verify_api_key
|
||||||
|
def get_alias(alias_id):
|
||||||
|
"""
|
||||||
|
Get alias
|
||||||
|
Input:
|
||||||
|
alias_id: in url
|
||||||
|
Output:
|
||||||
|
Alias info, same as in get_aliases
|
||||||
|
|
||||||
|
"""
|
||||||
|
user = g.user
|
||||||
|
alias: Alias = Alias.get(alias_id)
|
||||||
|
|
||||||
|
if alias.user_id != user.id:
|
||||||
|
return jsonify(error="Forbidden"), 403
|
||||||
|
|
||||||
|
return jsonify(**serialize_alias_info(get_alias_info(alias))), 200
|
||||||
|
|
||||||
|
|
||||||
def serialize_contact(fe: Contact) -> dict:
|
def serialize_contact(fe: Contact) -> dict:
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
|
|
|
@ -331,3 +331,37 @@ def test_delete_contact(flask_client):
|
||||||
|
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json == {"deleted": True}
|
assert r.json == {"deleted": True}
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_alias(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()
|
||||||
|
|
||||||
|
# create more aliases than PAGE_LIMIT
|
||||||
|
alias = Alias.create_new_random(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# get aliases on the 1st page, should return PAGE_LIMIT aliases
|
||||||
|
r = flask_client.get(
|
||||||
|
url_for("api.get_alias", alias_id=alias.id),
|
||||||
|
headers={"Authentication": api_key.code},
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
# assert returned field
|
||||||
|
res = r.json
|
||||||
|
assert "id" in res
|
||||||
|
assert "email" in res
|
||||||
|
assert "creation_date" in res
|
||||||
|
assert "creation_timestamp" in res
|
||||||
|
assert "nb_forward" in res
|
||||||
|
assert "nb_block" in res
|
||||||
|
assert "nb_reply" in res
|
||||||
|
assert "enabled" in res
|
||||||
|
assert "note" in res
|
||||||
|
|
Loading…
Reference in New Issue