mirror of
https://github.com/simple-login/app.git
synced 2025-09-13 01:55:48 +08:00
fix: commit alias deletion on API + add filter on trashed aliases in api (#2470)
This commit is contained in:
parent
f7882e971e
commit
b13a07bd6b
3 changed files with 37 additions and 3 deletions
|
@ -120,7 +120,7 @@ def get_alias_infos_with_pagination(user, page_id=0, query=None) -> [AliasInfo]:
|
|||
q = (
|
||||
Session.query(Alias)
|
||||
.options(joinedload(Alias.mailbox))
|
||||
.filter(Alias.user_id == user.id)
|
||||
.filter(Alias.user_id == user.id, Alias.delete_on == None) # noqa: E711
|
||||
.order_by(Alias.created_at.desc())
|
||||
)
|
||||
|
||||
|
|
|
@ -165,7 +165,8 @@ def delete_alias(alias_id):
|
|||
if not alias or alias.user_id != user.id:
|
||||
return jsonify(error="Forbidden"), 403
|
||||
|
||||
alias_delete.delete_alias(alias, user, AliasDeleteReason.ManualAction)
|
||||
LOG.i(f"User {user} is deleting alias {alias}")
|
||||
alias_delete.delete_alias(alias, user, AliasDeleteReason.ManualAction, commit=True)
|
||||
|
||||
return jsonify(deleted=True), 200
|
||||
|
||||
|
|
|
@ -3,9 +3,10 @@ from flask import url_for
|
|||
|
||||
# Need to import directly from config to allow modification from the tests
|
||||
from app import config
|
||||
from app.alias_delete import move_alias_to_trash
|
||||
from app.db import Session
|
||||
from app.email_utils import is_reverse_alias
|
||||
from app.models import User, Alias, Contact, EmailLog, Mailbox
|
||||
from app.models import User, Alias, Contact, EmailLog, Mailbox, AliasDeleteReason
|
||||
from tests.api.utils import get_new_user_and_api_key
|
||||
from tests.utils import login, random_domain
|
||||
|
||||
|
@ -692,3 +693,35 @@ def test_get_aliases_disabled_account(flask_client):
|
|||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
assert r.status_code == 403
|
||||
|
||||
|
||||
def test_get_aliases_does_not_return_trashed_aliases(flask_client):
|
||||
user, api_key = get_new_user_and_api_key()
|
||||
|
||||
alias = Alias.create_new_random(user)
|
||||
|
||||
r = flask_client.get(
|
||||
"/api/v2/aliases?page_id=0",
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
aliases = r.json["aliases"]
|
||||
assert len(aliases) == 2 # Newsletter + our own
|
||||
|
||||
assert aliases[0]["id"] == alias.id
|
||||
|
||||
newsletter_alias_id = aliases[1]["id"]
|
||||
assert newsletter_alias_id != alias.id
|
||||
|
||||
move_alias_to_trash(alias, user, AliasDeleteReason.ManualAction, commit=True)
|
||||
|
||||
r = flask_client.get(
|
||||
"/api/v2/aliases?page_id=0",
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
aliases = r.json["aliases"]
|
||||
assert len(aliases) == 1 # Newsletter
|
||||
assert aliases[0]["id"] == newsletter_alias_id
|
||||
|
|
Loading…
Add table
Reference in a new issue