use the alias v2 format for GET /api/aliases/:alias_id, POST /api/v2/alias/custom/new, POST /api/v2/alias/random/new
This commit is contained in:
parent
8777db0729
commit
42b3666f45
76
README.md
76
README.md
|
@ -836,22 +836,7 @@ Input:
|
||||||
- (Optional) note: alias note
|
- (Optional) note: alias note
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
If success, 201 with the new alias, for example
|
If success, 201 with the new alias info. Use the same format as in GET /api/aliases/:alias_id
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"alias": "www_groupon_com@my_domain.com",
|
|
||||||
"creation_date": "2020-02-04 16:23:02+00:00",
|
|
||||||
"creation_timestamp": 1580833382,
|
|
||||||
"email": "www_groupon_com@my_domain.com",
|
|
||||||
"id": 4,
|
|
||||||
"nb_block": 0,
|
|
||||||
"nb_forward": 0,
|
|
||||||
"nb_reply": 0,
|
|
||||||
"enabled": true,
|
|
||||||
"note": "This is a note"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### POST /api/alias/random/new
|
#### POST /api/alias/random/new
|
||||||
|
|
||||||
|
@ -865,22 +850,7 @@ Input:
|
||||||
- (Optional) note: alias note
|
- (Optional) note: alias note
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
If success, 201 with the new alias, for example
|
If success, 201 with the new alias info. Use the same format as in GET /api/aliases/:alias_id
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"alias": "prefix.suffix@my_domain.com",
|
|
||||||
"creation_date": "2020-02-04 16:23:02+00:00",
|
|
||||||
"creation_timestamp": 1580833382,
|
|
||||||
"email": "www_groupon_com@my_domain.com",
|
|
||||||
"id": 4,
|
|
||||||
"nb_block": 0,
|
|
||||||
"nb_forward": 0,
|
|
||||||
"nb_reply": 0,
|
|
||||||
"enabled": true,
|
|
||||||
"note": "This is a note"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### GET /api/v2/aliases
|
#### GET /api/v2/aliases
|
||||||
|
|
||||||
|
@ -970,19 +940,43 @@ Input:
|
||||||
- `alias_id` in url
|
- `alias_id` in url
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
Alias info
|
Alias info, use the same format as in /api/v2/aliases. For example:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"creation_date": "2020-02-04 16:23:02+00:00",
|
"creation_date": "2020-04-06 17:57:14+00:00",
|
||||||
"creation_timestamp": 1580833382,
|
"creation_timestamp": 1586195834,
|
||||||
"email": "e3@.alo@sl.local",
|
"email": "prefix1.cat@sl.local",
|
||||||
"id": 4,
|
"name": "A Name",
|
||||||
"nb_block": 0,
|
|
||||||
"nb_forward": 0,
|
|
||||||
"nb_reply": 0,
|
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"note": "This is a note"
|
"id": 3,
|
||||||
|
"mailbox": {
|
||||||
|
"email": "a@b.c",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"mailboxes": [
|
||||||
|
{
|
||||||
|
"email": "m1@cd.ef",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "john@wick.com",
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"latest_activity": {
|
||||||
|
"action": "forward",
|
||||||
|
"contact": {
|
||||||
|
"email": "c1@example.com",
|
||||||
|
"name": null,
|
||||||
|
"reverse_alias": "\"c1 at example.com\" <re1@SL>"
|
||||||
|
},
|
||||||
|
"timestamp": 1586195834
|
||||||
|
},
|
||||||
|
"nb_block": 0,
|
||||||
|
"nb_forward": 1,
|
||||||
|
"nb_reply": 0,
|
||||||
|
"note": null
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,10 @@ def get_alias_info(alias: Alias) -> AliasInfo:
|
||||||
return alias_info
|
return alias_info
|
||||||
|
|
||||||
|
|
||||||
def get_alias_info_v2(alias: Alias, mailbox) -> AliasInfo:
|
def get_alias_info_v2(alias: Alias, mailbox=None) -> AliasInfo:
|
||||||
|
if not mailbox:
|
||||||
|
mailbox = alias.mailbox
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
db.session.query(Contact, EmailLog)
|
db.session.query(Contact, EmailLog)
|
||||||
.filter(Contact.alias_id == alias.id)
|
.filter(Contact.alias_id == alias.id)
|
||||||
|
|
|
@ -10,10 +10,10 @@ from app.api.serializer import (
|
||||||
serialize_alias_info,
|
serialize_alias_info,
|
||||||
serialize_contact,
|
serialize_contact,
|
||||||
get_alias_infos_with_pagination,
|
get_alias_infos_with_pagination,
|
||||||
get_alias_info,
|
|
||||||
get_alias_contacts,
|
get_alias_contacts,
|
||||||
get_alias_infos_with_pagination_v2,
|
get_alias_infos_with_pagination_v2,
|
||||||
serialize_alias_info_v2,
|
serialize_alias_info_v2,
|
||||||
|
get_alias_info_v2,
|
||||||
)
|
)
|
||||||
from app.config import EMAIL_DOMAIN
|
from app.config import EMAIL_DOMAIN
|
||||||
from app.dashboard.views.alias_log import get_alias_log
|
from app.dashboard.views.alias_log import get_alias_log
|
||||||
|
@ -327,7 +327,7 @@ def get_alias(alias_id):
|
||||||
if alias.user_id != user.id:
|
if alias.user_id != user.id:
|
||||||
return jsonify(error="Forbidden"), 403
|
return jsonify(error="Forbidden"), 403
|
||||||
|
|
||||||
return jsonify(**serialize_alias_info(get_alias_info(alias))), 200
|
return jsonify(**serialize_alias_info_v2(get_alias_info_v2(alias))), 200
|
||||||
|
|
||||||
|
|
||||||
@api_bp.route("/aliases/<int:alias_id>/contacts")
|
@api_bp.route("/aliases/<int:alias_id>/contacts")
|
||||||
|
|
|
@ -4,7 +4,7 @@ from flask_cors import cross_origin
|
||||||
from itsdangerous import SignatureExpired
|
from itsdangerous import SignatureExpired
|
||||||
|
|
||||||
from app.api.base import api_bp, require_api_auth
|
from app.api.base import api_bp, require_api_auth
|
||||||
from app.api.serializer import serialize_alias_info, get_alias_info
|
from app.api.serializer import serialize_alias_info, get_alias_info, serialize_alias_info_v2, get_alias_info_v2
|
||||||
from app.config import MAX_NB_EMAIL_FREE_PLAN
|
from app.config import MAX_NB_EMAIL_FREE_PLAN
|
||||||
from app.dashboard.views.custom_alias import verify_prefix_suffix, signer
|
from app.dashboard.views.custom_alias import verify_prefix_suffix, signer
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -170,4 +170,4 @@ def new_custom_alias_v2():
|
||||||
AliasUsedOn.create(alias_id=alias.id, hostname=hostname, user_id=alias.user_id)
|
AliasUsedOn.create(alias_id=alias.id, hostname=hostname, user_id=alias.user_id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify(alias=full_alias, **serialize_alias_info(get_alias_info(alias))), 201
|
return jsonify(alias=full_alias, **serialize_alias_info_v2(get_alias_info_v2(alias))), 201
|
||||||
|
|
|
@ -3,7 +3,10 @@ from flask import jsonify, request
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
|
|
||||||
from app.api.base import api_bp, require_api_auth
|
from app.api.base import api_bp, require_api_auth
|
||||||
from app.api.serializer import serialize_alias_info, get_alias_info
|
from app.api.serializer import (
|
||||||
|
get_alias_info_v2,
|
||||||
|
serialize_alias_info_v2,
|
||||||
|
)
|
||||||
from app.config import MAX_NB_EMAIL_FREE_PLAN
|
from app.config import MAX_NB_EMAIL_FREE_PLAN
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
|
@ -57,6 +60,6 @@ def new_random_alias():
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify(alias=alias.email, **serialize_alias_info(get_alias_info(alias))),
|
jsonify(alias=alias.email, **serialize_alias_info_v2(get_alias_info_v2(alias))),
|
||||||
201,
|
201,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue