mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 15:23:27 +08:00
Add GET /api/custom_domains/:custom_domain_id/trash
This commit is contained in:
parent
de495b9afe
commit
aee917a3ef
3 changed files with 73 additions and 2 deletions
|
@ -2,7 +2,7 @@ from flask import g
|
|||
from flask import jsonify
|
||||
|
||||
from app.api.base import api_bp, require_api_auth
|
||||
from app.models import CustomDomain
|
||||
from app.models import CustomDomain, DomainDeletedAlias
|
||||
|
||||
|
||||
def custom_domain_to_dict(custom_domain: CustomDomain):
|
||||
|
@ -21,3 +21,26 @@ def get_custom_domains():
|
|||
custom_domains = CustomDomain.filter_by(user_id=user.id).all()
|
||||
|
||||
return jsonify(custom_domains=[custom_domain_to_dict(cd) for cd in custom_domains])
|
||||
|
||||
|
||||
@api_bp.route("/custom_domains/<int:custom_domain_id>/trash", methods=["GET"])
|
||||
@require_api_auth
|
||||
def get_custom_domain_trash(custom_domain_id: int):
|
||||
user = g.user
|
||||
custom_domain = CustomDomain.get(custom_domain_id)
|
||||
if not custom_domain or custom_domain.user_id != user.id:
|
||||
return jsonify(error="Forbidden"), 403
|
||||
|
||||
domain_deleted_aliases = DomainDeletedAlias.filter_by(
|
||||
domain_id=custom_domain.id
|
||||
).all()
|
||||
|
||||
return jsonify(
|
||||
aliases=[
|
||||
{
|
||||
"alias": dda.email,
|
||||
"creation_timestamp": dda.created_at.timestamp,
|
||||
}
|
||||
for dda in domain_deleted_aliases
|
||||
]
|
||||
)
|
||||
|
|
21
docs/api.md
21
docs/api.md
|
@ -652,6 +652,27 @@ List of custom domains.
|
|||
}
|
||||
```
|
||||
|
||||
#### GET /api/custom_domains/:custom_domain_id/trash
|
||||
|
||||
Get deleted alias for a custom domain
|
||||
|
||||
Input:
|
||||
- `Authentication` header that contains the api key
|
||||
|
||||
Output:
|
||||
List of deleted alias.
|
||||
|
||||
```json
|
||||
{
|
||||
"aliases": [
|
||||
{
|
||||
"alias": "first@test1.org",
|
||||
"creation_timestamp": 1605464595
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Contact endpoints
|
||||
|
||||
#### DELETE /api/contacts/:contact_id
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
|
||||
from app.models import CustomDomain
|
||||
from app.alias_utils import delete_alias
|
||||
from app.models import CustomDomain, DomainDeletedAlias, Alias
|
||||
from tests.utils import login
|
||||
|
||||
|
||||
|
@ -23,3 +24,29 @@ def test_get_custom_domains(flask_client):
|
|||
{"domain": "test2.org", "id": 2, "nb_alias": 0, "verified": False},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def test_get_custom_domain_trash(flask_client):
|
||||
user = login(flask_client)
|
||||
|
||||
cd = CustomDomain.create(
|
||||
user_id=user.id, domain="test1.org", verified=True, commit=True
|
||||
)
|
||||
|
||||
alias = Alias.create(
|
||||
user_id=user.id,
|
||||
email="first@test1.org",
|
||||
custom_domain_id=cd.id,
|
||||
mailbox_id=user.default_mailbox_id,
|
||||
commit=True,
|
||||
)
|
||||
|
||||
delete_alias(alias, user)
|
||||
|
||||
r = flask_client.get(
|
||||
f"/api/custom_domains/{cd.id}/trash",
|
||||
)
|
||||
|
||||
for deleted_alias in r.json["aliases"]:
|
||||
assert deleted_alias["alias"]
|
||||
assert deleted_alias["creation_timestamp"] > 0
|
||||
|
|
Loading…
Reference in a new issue