diff --git a/app/admin_model.py b/app/admin_model.py
index 03830a39..1906019f 100644
--- a/app/admin_model.py
+++ b/app/admin_model.py
@@ -1,5 +1,5 @@
from __future__ import annotations
-from typing import Optional
+from typing import Optional, List
import arrow
import sqlalchemy
@@ -35,6 +35,8 @@ from app.models import (
DomainDeletedAlias,
PartnerUser,
AliasMailbox,
+ AliasAuditLog,
+ UserAuditLog,
)
from app.newsletter_utils import send_newsletter_to_user, send_newsletter_to_address
@@ -737,11 +739,13 @@ class InvalidMailboxDomainAdmin(SLModelView):
class EmailSearchResult:
no_match: bool = True
alias: Optional[Alias] = None
- mailbox: list[Mailbox] = []
+ alias_audit_log: Optional[List[AliasAuditLog]] = None
+ mailbox: List[Mailbox] = []
mailbox_count: int = 0
deleted_alias: Optional[DeletedAlias] = None
deleted_custom_alias: Optional[DomainDeletedAlias] = None
user: Optional[User] = None
+ user_audit_log: Optional[List[UserAuditLog]] = None
@staticmethod
def from_email(email: str) -> EmailSearchResult:
@@ -749,10 +753,20 @@ class EmailSearchResult:
alias = Alias.get_by(email=email)
if alias:
output.alias = alias
+ output.alias_audit_log = (
+ AliasAuditLog.filter_by(alias_id=alias.id)
+ .order_by(AliasAuditLog.created_at.desc())
+ .all()
+ )
output.no_match = False
user = User.get_by(email=email)
if user:
output.user = user
+ output.user_audit_log = (
+ UserAuditLog.filter_by(user_id=user.id)
+ .order_by(UserAuditLog.created_at.desc())
+ .all()
+ )
output.no_match = False
mailboxes = (
Mailbox.filter_by(email=email).order_by(Mailbox.id.desc()).limit(10).all()
diff --git a/templates/admin/email_search.html b/templates/admin/email_search.html
index 8498fbae..da538ca5 100644
--- a/templates/admin/email_search.html
+++ b/templates/admin/email_search.html
@@ -154,6 +154,56 @@
{{ show_user(data.domain_deleted_alias.domain.user) }}
{%- endmacro %}
+{% macro list_alias_audit_log(alias_audit_log) %}
+
Alias Audit Log
+
+
+
+ User ID |
+ Alias ID |
+ Alias Email |
+ Action |
+ Message |
+ Time |
+
+
+
+ {% for entry in alias_audit_log %}
+
+ {{ entry.user_id }} |
+ {{ entry.alias_id }} |
+ {{ entry.alias_email }} |
+ {{ entry.action }} |
+ {{ entry.message }} |
+ {{ entry.created_at }} |
+
+ {% endfor %}
+
+
+{% endmacro %}
+{% macro list_user_audit_log(user_audit_log) %}
+ User Audit Log
+
+
+
+ User email |
+ Action |
+ Message |
+ Time |
+
+
+
+ {% for entry in user_audit_log %}
+
+ {{ entry.user_email }} |
+ {{ entry.action }} |
+ {{ entry.message }} |
+ {{ entry.created_at }} |
+
+ {% endfor %}
+
+
+{% endmacro %}
{% block body %}
@@ -177,6 +227,7 @@
Found Alias {{ data.alias.email }}
{{ list_alias(1,[data.alias]) }}
+ {{ list_alias_audit_log(data.alias_audit_log) }}
{{ list_mailboxes("Mailboxes for alias", helper.alias_mailbox_count(data.alias), helper.alias_mailboxes(data.alias)) }}
{{ show_user(data.alias.user) }}
@@ -188,6 +239,7 @@
{{ show_user(data.user) }}
{{ list_mailboxes("Mailboxes for user", helper.mailbox_count(data.user) , helper.mailbox_list(data.user) ) }}
{{ list_alias(helper.alias_count(data.user) ,helper.alias_list(data.user)) }}
+ {{ list_user_audit_log(data.user_audit_log) }}
{% endif %}
{% if data.mailbox_count > 10 %}