mirror of
https://github.com/simple-login/app.git
synced 2025-10-08 06:24:50 +08:00
* wip: start implementing alias trash * Added alias trash dashboard page * test: delete_alias changes * Format html * fix: mailbox deletion * feat: add delete_alias_action setting in dashboard settings * chore: disable alias when trashing it * Add restore tests * Move tras/restore to alias_actions * rename alias_actions to alias_delete * Remove alias_actions * Send events and alias audit log on alias restore * feat: adapt queries to trashed alias * chore: add metrics on alias trash actions * fix: missing empty arg * Add rate limit for restore and restore all * fix: mailbox alias count * feat: properly handle alias deletion for custom domain deletion * chore: add error logs * chore: update alias trash copy + change Trash location * feat: make can_create_new_alias not take trashed aliases into account * chore: update mailbox deletion dialog copy --------- Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from typing import List
|
|
|
|
from app.alias_audit_log_utils import AliasAuditLogAction
|
|
from app.alias_delete import move_alias_to_trash
|
|
from app.db import Session
|
|
from app.models import CustomDomain, Alias, User, AliasAuditLog
|
|
from tasks.delete_custom_domain_job import DeleteCustomDomainJob
|
|
from tests.utils import create_new_user, random_domain, random_email
|
|
|
|
|
|
def alias_for_domain(user: User, domain: CustomDomain, trashed: bool = False) -> Alias:
|
|
alias = Alias.create(
|
|
user_id=user.id,
|
|
email=random_email(),
|
|
mailbox_id=user.default_mailbox_id,
|
|
custom_domain_id=domain.id,
|
|
)
|
|
if trashed:
|
|
move_alias_to_trash(alias, user)
|
|
Session.commit()
|
|
return alias
|
|
|
|
|
|
def assert_alias_audit_log(
|
|
alias_id: int, expected_length: int, expected_last_action: AliasAuditLogAction
|
|
):
|
|
audit_logs: List[AliasAuditLog] = AliasAuditLog.filter_by(alias_id=alias_id).all()
|
|
assert len(audit_logs) == expected_length
|
|
assert audit_logs[expected_length - 1].action == expected_last_action.value
|
|
|
|
|
|
def test_delete_custom_domain_removes_aliases():
|
|
user = create_new_user()
|
|
|
|
cd = CustomDomain.create(user_id=user.id, domain=random_domain())
|
|
a1 = alias_for_domain(user, cd)
|
|
a2 = alias_for_domain(user, cd, True)
|
|
|
|
a1_id = a1.id
|
|
a2_id = a2.id
|
|
|
|
job = DeleteCustomDomainJob(cd)
|
|
job.run()
|
|
|
|
assert_alias_audit_log(a1_id, 2, AliasAuditLogAction.DeleteAlias)
|
|
assert_alias_audit_log(a2_id, 3, AliasAuditLogAction.DeleteAlias)
|