mirror of
https://github.com/simple-login/app.git
synced 2025-09-12 17:45:18 +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>
62 lines
2 KiB
Python
62 lines
2 KiB
Python
from typing import Optional
|
|
|
|
from app.db import Session
|
|
from app.email_utils import send_email
|
|
from app.log import LOG
|
|
from app.models import Job, CustomDomain
|
|
from app.user_audit_log_utils import emit_user_audit_log, UserAuditLogAction
|
|
|
|
|
|
class DeleteCustomDomainJob:
|
|
def __init__(self, custom_domain: CustomDomain):
|
|
self.custom_domain = custom_domain
|
|
|
|
@staticmethod
|
|
def create_from_job(job: Job) -> Optional["DeleteCustomDomainJob"]:
|
|
custom_domain_id = job.payload.get("custom_domain_id")
|
|
if not custom_domain_id:
|
|
LOG.error(
|
|
f"Job {job.id} did not have custom_domain_id property. Payload: {job.payload}"
|
|
)
|
|
return None
|
|
custom_domain: Optional[CustomDomain] = CustomDomain.get(custom_domain_id)
|
|
if not custom_domain:
|
|
LOG.error(f"Could not find CustomDomain: {custom_domain_id}")
|
|
return None
|
|
|
|
return DeleteCustomDomainJob(custom_domain)
|
|
|
|
def run(self):
|
|
custom_domain_id = self.custom_domain.id
|
|
is_subdomain = self.custom_domain.is_sl_subdomain
|
|
domain_name = self.custom_domain.domain
|
|
user = self.custom_domain.user
|
|
|
|
custom_domain_partner_id = self.custom_domain.partner_id
|
|
CustomDomain.delete(self.custom_domain.id)
|
|
Session.commit()
|
|
|
|
if is_subdomain:
|
|
message = f"Delete subdomain {custom_domain_id} ({domain_name})"
|
|
else:
|
|
message = f"Delete custom domain {custom_domain_id} ({domain_name})"
|
|
emit_user_audit_log(
|
|
user=user,
|
|
action=UserAuditLogAction.DeleteCustomDomain,
|
|
message=message,
|
|
commit=True,
|
|
)
|
|
|
|
LOG.d("Domain %s deleted", domain_name)
|
|
|
|
if custom_domain_partner_id is None:
|
|
send_email(
|
|
user.email,
|
|
f"Your domain {domain_name} has been deleted",
|
|
f"""Domain {domain_name} along with its aliases are deleted successfully.
|
|
|
|
Regards,
|
|
SimpleLogin team.
|
|
""",
|
|
retries=3,
|
|
)
|