diff --git a/README.md b/README.md index b14b3c46..5ac0a32a 100644 --- a/README.md +++ b/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\" " + }, + "timestamp": 1586195834 + }, + "nb_block": 0, + "nb_forward": 1, + "nb_reply": 0, + "note": null } ``` diff --git a/app/api/base.py b/app/api/base.py index 0c306e62..36d9bd50 100644 --- a/app/api/base.py +++ b/app/api/base.py @@ -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") diff --git a/app/api/serializer.py b/app/api/serializer.py index faa4c91e..8c2f85f9 100644 --- a/app/api/serializer.py +++ b/app/api/serializer.py @@ -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) diff --git a/app/api/views/alias.py b/app/api/views/alias.py index 7635a77e..54daccfc 100644 --- a/app/api/views/alias.py +++ b/app/api/views/alias.py @@ -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//contacts") diff --git a/app/api/views/mailbox.py b/app/api/views/mailbox.py index deea4bbe..0e26c9c9 100644 --- a/app/api/views/mailbox.py +++ b/app/api/views/mailbox.py @@ -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 diff --git a/app/api/views/new_custom_alias.py b/app/api/views/new_custom_alias.py index afca282a..55dc55c9 100644 --- a/app/api/views/new_custom_alias.py +++ b/app/api/views/new_custom_alias.py @@ -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, + ) diff --git a/app/api/views/new_random_alias.py b/app/api/views/new_random_alias.py index 26def73e..9a7bdcdc 100644 --- a/app/api/views/new_random_alias.py +++ b/app/api/views/new_random_alias.py @@ -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, )