Email search improvements

This commit is contained in:
Adrià Casajús 2024-09-02 16:58:14 +02:00
parent 728f9bf1f8
commit 5b0fd3cee4
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
2 changed files with 38 additions and 11 deletions

View File

@ -33,6 +33,7 @@ from app.models import (
Mailbox, Mailbox,
DeletedAlias, DeletedAlias,
DomainDeletedAlias, DomainDeletedAlias,
PartnerUser,
) )
from app.newsletter_utils import send_newsletter_to_user, send_newsletter_to_address from app.newsletter_utils import send_newsletter_to_user, send_newsletter_to_address
@ -747,22 +748,18 @@ class EmailSearchResult:
if alias: if alias:
output.alias = alias output.alias = alias
output.no_match = False output.no_match = False
return output
user = User.get_by(email=email) user = User.get_by(email=email)
if user: if user:
output.user = user output.user = user
output.no_match = False output.no_match = False
return output
mailbox = Mailbox.get_by(email=email) mailbox = Mailbox.get_by(email=email)
if mailbox: if mailbox:
output.mailbox = mailbox output.mailbox = mailbox
output.no_match = False output.no_match = False
return output
deleted_alias = DeletedAlias.get_by(email=email) deleted_alias = DeletedAlias.get_by(email=email)
if deleted_alias: if deleted_alias:
output.deleted_alias = deleted_alias output.deleted_alias = deleted_alias
output.no_match = False output.no_match = False
return output
domain_deleted_alias = DomainDeletedAlias.get_by(email=email) domain_deleted_alias = DomainDeletedAlias.get_by(email=email)
if domain_deleted_alias: if domain_deleted_alias:
output.domain_deleted_alias = domain_deleted_alias output.domain_deleted_alias = domain_deleted_alias
@ -792,6 +789,10 @@ class EmailSearchHelpers:
def alias_count(user: User) -> int: def alias_count(user: User) -> int:
return Alias.filter_by(user_id=user.id).count() return Alias.filter_by(user_id=user.id).count()
@staticmethod
def partner_user(user: User) -> Optional[PartnerUser]:
return PartnerUser.get_by(user_id=user.id)
class EmailSearchAdmin(BaseView): class EmailSearchAdmin(BaseView):
def is_accessible(self): def is_accessible(self):

View File

@ -2,23 +2,40 @@
{% macro show_user(user) -%} {% macro show_user(user) -%}
<h4>User {{ user.email }} with ID {{ user.id }}.</h4> <h4>User {{ user.email }} with ID {{ user.id }}.</h4>
{% set pu = helper.partner_user(user) %}
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th scope="col">User ID</th> <th scope="col">User ID</th>
<th scope="col">Email</th> <th scope="col">Email</th>
<th scope="col">Status</th>
<th scope="col">Paid</th> <th scope="col">Paid</th>
<th>Subscription</th> <th>Subscription</th>
<th>Created At</th> <th>Created At</th>
<th>Updated At</th>
<th>Connected with Proton account</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>{{ user.id }}</td> <td>{{ user.id }}</td>
<td>{{ user.email }}</td> <td>{{ user.email }}</td>
<td>{{ "yes" if user.is_paid() else No }}</td> {% if user.disabled %}
<td class="text-danger">Disabled</td>
{% else %}
<td class="text-success">Enabled</td>
{% endif %}
<td>{{ "yes" if user.is_paid() else "No" }}</td>
<td>{{ user.get_active_subscription() }}</td> <td>{{ user.get_active_subscription() }}</td>
<td>{{ user.created_at }}</td> <td>{{ user.created_at }}</td>
<td>{{ user.updated_at }}</td>
{% if pu %}
<td>{{ pu.partner_email }}</td>
{% else %}
<td>No</td>
{% endif %}
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -44,7 +61,9 @@
<td>{{ mailbox.id }}</td> <td>{{ mailbox.id }}</td>
<td>{{ mailbox.email }}</td> <td>{{ mailbox.email }}</td>
<td>{{ "Yes" if mailbox.verified else "No" }}</td> <td>{{ "Yes" if mailbox.verified else "No" }}</td>
<td>{{ mailbox.created_at }}</td> <td>
{{ mailbox.created_at }}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -58,15 +77,22 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Alias ID</th> <th>
<th>Email</th> Alias ID
<th>Verified</th> </th>
<th>Created At</th> <th>
Email
</th>
<th>
Verified
</th>
<th>
Created At
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for alias in aliases %} {% for alias in aliases %}
<tr> <tr>
<td>{{ alias.id }}</td> <td>{{ alias.id }}</td>
<td>{{ alias.email }}</td> <td>{{ alias.email }}</td>