Merge pull request #206 from simple-login/normalize-api-response
Normalize api response
This commit is contained in:
commit
1ded0c3e26
78
README.md
78
README.md
|
@ -836,22 +836,7 @@ Input:
|
|||
- (Optional) note: alias note
|
||||
|
||||
Output:
|
||||
If success, 201 with the new alias, for example
|
||||
|
||||
```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"
|
||||
}
|
||||
```
|
||||
If success, 201 with the new alias info. Use the same format as in GET /api/aliases/:alias_id
|
||||
|
||||
#### POST /api/alias/random/new
|
||||
|
||||
|
@ -865,22 +850,7 @@ Input:
|
|||
- (Optional) note: alias note
|
||||
|
||||
Output:
|
||||
If success, 201 with the new alias, for example
|
||||
|
||||
```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"
|
||||
}
|
||||
```
|
||||
If success, 201 with the new alias info. Use the same format as in GET /api/aliases/:alias_id
|
||||
|
||||
#### GET /api/v2/aliases
|
||||
|
||||
|
@ -970,19 +940,43 @@ Input:
|
|||
- `alias_id` in url
|
||||
|
||||
Output:
|
||||
Alias info
|
||||
Alias info, use the same format as in /api/v2/aliases. For example:
|
||||
|
||||
```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"
|
||||
"creation_date": "2020-04-06 17:57:14+00:00",
|
||||
"creation_timestamp": 1586195834,
|
||||
"email": "prefix1.cat@sl.local",
|
||||
"name": "A Name",
|
||||
"enabled": true,
|
||||
"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
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ from flask import Blueprint, request, jsonify, g
|
|||
from flask_login import current_user
|
||||
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import ApiKey
|
||||
|
||||
api_bp = Blueprint(name="api", import_name=__name__, url_prefix="/api")
|
||||
|
|
|
@ -207,7 +207,10 @@ def get_alias_info(alias: Alias) -> AliasInfo:
|
|||
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 = (
|
||||
db.session.query(Contact, EmailLog)
|
||||
.filter(Contact.alias_id == alias.id)
|
||||
|
|
|
@ -10,10 +10,10 @@ from app.api.serializer import (
|
|||
serialize_alias_info,
|
||||
serialize_contact,
|
||||
get_alias_infos_with_pagination,
|
||||
get_alias_info,
|
||||
get_alias_contacts,
|
||||
get_alias_infos_with_pagination_v2,
|
||||
serialize_alias_info_v2,
|
||||
get_alias_info_v2,
|
||||
)
|
||||
from app.config import EMAIL_DOMAIN
|
||||
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:
|
||||
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")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from smtplib import SMTPRecipientsRefused
|
||||
|
||||
from flask import g, jsonify
|
||||
from flask import g
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
from flask_cors import cross_origin
|
||||
|
|
|
@ -4,7 +4,12 @@ from flask_cors import cross_origin
|
|||
from itsdangerous import SignatureExpired
|
||||
|
||||
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.dashboard.views.custom_alias import verify_prefix_suffix, signer
|
||||
from app.extensions import db
|
||||
|
@ -170,4 +175,7 @@ def new_custom_alias_v2():
|
|||
AliasUsedOn.create(alias_id=alias.id, hostname=hostname, user_id=alias.user_id)
|
||||
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 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.extensions import db
|
||||
from app.log import LOG
|
||||
|
@ -57,6 +60,6 @@ def new_random_alias():
|
|||
db.session.commit()
|
||||
|
||||
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,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue