mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Quotas page improvements:
* Possibility to filter mailboxes using a search pattern * Possibility to edit a mailbox fixes #391
This commit is contained in:
+16
-4
@@ -317,21 +317,33 @@ class User(DUser):
|
||||
domaliases += dom.domainalias_set.all()
|
||||
return domaliases
|
||||
|
||||
def get_mailboxes(self):
|
||||
def get_mailboxes(self, squery=None):
|
||||
"""Return the mailboxes that belong to this user
|
||||
|
||||
The result will contain the mailboxes defined for each domain that
|
||||
user can see.
|
||||
|
||||
:param string squery: a search query
|
||||
:return: a list of ``Mailbox`` objects
|
||||
"""
|
||||
from modoboa.lib.permissions import get_content_type
|
||||
|
||||
if self.is_superuser:
|
||||
return Mailbox.objects.all()
|
||||
qf = None
|
||||
if squery is not None:
|
||||
if '@' in squery:
|
||||
parts = squery.split('@')
|
||||
addrfilter = '@'.join(parts[:-1])
|
||||
domfilter = parts[-1]
|
||||
qf = Q(address__contains=addrfilter) & Q(domain__name__contains=domfilter)
|
||||
else:
|
||||
qf = Q(address__contains=squery) | Q(domain__name__contains=squery)
|
||||
ids = self.objectaccess_set.filter(content_type=get_content_type(Mailbox)) \
|
||||
.values_list('object_id', flat=True)
|
||||
return Mailbox.objects.filter(pk__in=ids)
|
||||
if qf is not None:
|
||||
qf = Q(pk__in=ids) & qf
|
||||
else:
|
||||
qf = Q(pk__in=ids)
|
||||
return Mailbox.objects.filter(qf)
|
||||
|
||||
def get_mbaliases(self):
|
||||
"""Return the mailbox aliases that belong to this user
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load i18n libextras %}
|
||||
{% load i18n libextras admin_extras %}
|
||||
<table class="table table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -10,7 +10,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for mbox in mboxes %}<tr>
|
||||
<td>{{ mbox.full_address }}</td>
|
||||
<td>{% identity_modify_link mbox.user "mail" %}</td>
|
||||
<td>{{ mbox.get_quota }}M</td>
|
||||
<td>{{ mbox.quota }}M</td>
|
||||
<td name="quota">
|
||||
|
||||
@@ -212,10 +212,11 @@ def identity_actions(user, ident):
|
||||
return render_actions(actions)
|
||||
|
||||
@register.simple_tag
|
||||
def identity_modify_link(identity):
|
||||
def identity_modify_link(identity, active_tab='default'):
|
||||
linkdef = {"label" : identity.identity, "modal" : True}
|
||||
if identity.__class__.__name__ == "User":
|
||||
linkdef["url"] = reverse("modoboa.admin.views.editaccount", args=[identity.id])
|
||||
linkdef["url"] += "?active_tab=%s" % active_tab
|
||||
linkdef["modalcb"] = "admin.editaccount_cb"
|
||||
else:
|
||||
linkdef["url"] = reverse("modoboa.admin.views.editalias_dispatcher", args=[identity.id])
|
||||
|
||||
@@ -345,7 +345,8 @@ def mboxes_list(request):
|
||||
@permission_required("admin.add_mailbox")
|
||||
def list_quotas(request, tplname="admin/quotas.html"):
|
||||
sort_order = request.GET.get("sort_order", "address")
|
||||
mboxes = request.user.get_mailboxes()
|
||||
mboxes = request.user.get_mailboxes(request.GET.get("searchquery", None))
|
||||
mboxes = mboxes.exclude(quota=0)
|
||||
if sort_order.startswith("-"):
|
||||
sort_dir = "-"
|
||||
sort_order = sort_order[1:]
|
||||
@@ -475,6 +476,9 @@ def editaccount(request, accountid, tplname="common/tabforms.html"):
|
||||
return ajax_response(request, status="ko", template=tplname, **ctx)
|
||||
|
||||
ctx["tabs"] = AccountForm(request.user, instances=instances)
|
||||
active_tab_id = request.GET.get("active_tab", "default")
|
||||
if active_tab_id != "default":
|
||||
ctx["tabs"].active_id = active_tab_id
|
||||
return render(request, tplname, ctx)
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user