mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +01:00
AdminPanel: Show up to 10 mailboxes found (#2204)
* AdminPanel: Show up to 10 mailboxes found * Add links
This commit is contained in:
parent
1fb2e8f01c
commit
cc44247482
2 changed files with 32 additions and 22 deletions
|
@ -736,7 +736,8 @@ class InvalidMailboxDomainAdmin(SLModelView):
|
|||
class EmailSearchResult:
|
||||
no_match: bool = True
|
||||
alias: Optional[Alias] = None
|
||||
mailbox: Optional[Mailbox] = None
|
||||
mailbox: list[Mailbox] = []
|
||||
mailbox_count: int = 0
|
||||
deleted_alias: Optional[DeletedAlias] = None
|
||||
deleted_custom_alias: Optional[DomainDeletedAlias] = None
|
||||
user: Optional[User] = None
|
||||
|
@ -752,9 +753,12 @@ class EmailSearchResult:
|
|||
if user:
|
||||
output.user = user
|
||||
output.no_match = False
|
||||
mailbox = Mailbox.get_by(email=email)
|
||||
if mailbox:
|
||||
output.mailbox = mailbox
|
||||
mailboxes = (
|
||||
Mailbox.filter_by(email=email).order_by(Mailbox.id.desc()).limit(10).all()
|
||||
)
|
||||
if mailboxes:
|
||||
output.mailbox = mailboxes
|
||||
output.mailbox_count = Mailbox.filter_by(email=email).count()
|
||||
output.no_match = False
|
||||
deleted_alias = DeletedAlias.get_by(email=email)
|
||||
if deleted_alias:
|
||||
|
@ -779,11 +783,13 @@ class EmailSearchHelpers:
|
|||
|
||||
@staticmethod
|
||||
def mailbox_count(user: User) -> int:
|
||||
return Mailbox.filter_by(user_id=user.id).order_by(Mailbox.id.asc()).count()
|
||||
return Mailbox.filter_by(user_id=user.id).order_by(Mailbox.id.desc()).count()
|
||||
|
||||
@staticmethod
|
||||
def alias_list(user: User) -> list[Alias]:
|
||||
return Alias.filter_by(user_id=user.id).order_by(Alias.id.asc()).limit(10).all()
|
||||
return (
|
||||
Alias.filter_by(user_id=user.id).order_by(Alias.id.desc()).limit(10).all()
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def alias_count(user: User) -> int:
|
||||
|
@ -806,9 +812,8 @@ class EmailSearchAdmin(BaseView):
|
|||
@expose("/", methods=["GET", "POST"])
|
||||
def index(self):
|
||||
search = EmailSearchResult()
|
||||
email = ""
|
||||
if request.form and request.form["email"]:
|
||||
email = request.form["email"]
|
||||
email = request.args.get("email")
|
||||
if email is not None and len(email) > 0:
|
||||
email = email.strip()
|
||||
search = EmailSearchResult.from_email(email)
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td>{{ user.id }}</td>
|
||||
<td>{{ user.email }}</td>
|
||||
<td><a href="?email={{ user.email }}">{{ user.email }}</a></td>
|
||||
{% if user.disabled %}
|
||||
|
||||
<td class="text-danger">Disabled</td>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<td>{{ user.updated_at }}</td>
|
||||
{% if pu %}
|
||||
|
||||
<td>{{ pu.partner_email }}</td>
|
||||
<td><a href="?email={{ pu.partner_email }}">{{ pu.partner_email }}</a></td>
|
||||
{% else %}
|
||||
<td>No</td>
|
||||
{% endif %}
|
||||
|
@ -43,7 +43,7 @@
|
|||
{% macro list_mailboxes(mbox_count, mboxes) %}
|
||||
<h4>
|
||||
{{ mbox_count }} Mailboxes found.
|
||||
{% if mbox_count>10 %}Showing only the first 10.{% endif %}
|
||||
{% if mbox_count>10 %}Showing only the last 10.{% endif %}
|
||||
</h4>
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
@ -59,7 +59,7 @@
|
|||
|
||||
<tr>
|
||||
<td>{{ mailbox.id }}</td>
|
||||
<td>{{ mailbox.email }}</td>
|
||||
<td><a href="?email={{mailbox.email}}">{{mailbox.email}}</a></td>
|
||||
<td>{{ "Yes" if mailbox.verified else "No" }}</td>
|
||||
<td>
|
||||
{{ mailbox.created_at }}
|
||||
|
@ -72,7 +72,7 @@
|
|||
{% macro list_alias(alias_count, aliases) %}
|
||||
<h4>
|
||||
{{ alias_count }} Aliases found.
|
||||
{% if alias_count>10 %}Showing only the first 10.{% endif %}
|
||||
{% if alias_count>10 %}Showing only the last 10.{% endif %}
|
||||
</h4>
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
@ -95,7 +95,7 @@
|
|||
{% for alias in aliases %}
|
||||
<tr>
|
||||
<td>{{ alias.id }}</td>
|
||||
<td>{{ alias.email }}</td>
|
||||
<td><a href="?email={{alias.email}}">{{alias.email}}</a></td>
|
||||
<td>{{ "Yes" if alias.verified else "No" }}</td>
|
||||
<td>{{ alias.created_at }}</td>
|
||||
</tr>
|
||||
|
@ -156,7 +156,7 @@
|
|||
{% block body %}
|
||||
|
||||
<div class="border border-dark border-2 mt-1 mb-2 p-3">
|
||||
<form method="post">
|
||||
<form method="get">
|
||||
<div class="form-group">
|
||||
<label for="email">Email to search:</label>
|
||||
<input type="text"
|
||||
|
@ -167,7 +167,7 @@
|
|||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
{% if no_match %}
|
||||
{% if data.no_match and email %}
|
||||
|
||||
<div class="border border-dark border-2 mt-1 mb-2 p-3 alert alert-warning"
|
||||
role="alert">No user, alias or mailbox found for {{ email }}</div>
|
||||
|
@ -190,14 +190,19 @@
|
|||
{{ list_alias(helper.alias_count(data.user) ,helper.alias_list(data.user)) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if data.mailbox %}
|
||||
{% if data.mailbox_count > 10 %}
|
||||
<h3>Found more than 10 mailboxes for {{ email }}. Showing the last 10</h3>
|
||||
{% elif data.mailbox_count > 0 %}
|
||||
<h3>Found {{ data.mailbox_count }} mailbox(es) for {{ email }}</h3>
|
||||
{% endif %}
|
||||
{% for mailbox in data.mailbox %}
|
||||
|
||||
<div class="border border-dark mt-1 mb-2 p-3">
|
||||
<h3 class="mb-3">Found Mailbox {{ data.mailbox.email }}</h3>
|
||||
{{ list_mailboxes(1, [data.mailbox]) }}
|
||||
{{ show_user(data.mailbox.user) }}
|
||||
<h3 class="mb-3">Found Mailbox {{ mailbox.email }}</h3>
|
||||
{{ list_mailboxes(1, [mailbox]) }}
|
||||
{{ show_user(mailbox.user) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.deleted_alias %}
|
||||
|
||||
<div class="border border-dark mt-1 mb-2 p-3">
|
||||
|
|
Loading…
Reference in a new issue