mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Not so easy to load a ChoiceField dynamically...
This commit is contained in:
+2
-2
@@ -41,5 +41,5 @@ class PermissionForm(forms.Form):
|
||||
required=True)
|
||||
user = forms.ChoiceField(label=_("User"), required=True)
|
||||
role = forms.ChoiceField(label=_("Role"), required=True,
|
||||
choices=(("SuperAdmin", _("Super administrator")),
|
||||
("DomainAdmin", _("Domain administrator"))))
|
||||
choices=(("SuperAdmins", _("Super administrator")),
|
||||
("DomainAdmins", _("Domain administrator"))))
|
||||
|
||||
+8
-4
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext as _
|
||||
from django.core import serializers
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User, Group
|
||||
from mailng import admin
|
||||
from mailng.admin.models import Domain, Mailbox, Alias
|
||||
from forms import MailboxForm, DomainForm, AliasForm, PermissionForm
|
||||
@@ -297,14 +297,18 @@ def settings(request):
|
||||
def addpermission(request):
|
||||
if request.method == "POST":
|
||||
form = PermissionForm(request.POST)
|
||||
if request.POST.has_key('user'):
|
||||
mboxid = request.POST['user']
|
||||
form.fields["user"].choices = \
|
||||
[(mboxid, Mailbox.objects.get(pk=mboxid)),]
|
||||
if form.is_valid():
|
||||
mb = Mailbox.objects.get(pk=request.POST["user"])
|
||||
if request.POST["role"] == "SuperAdmin":
|
||||
if request.POST["role"] == "SuperAdmins":
|
||||
mb.user.is_superadmin = True
|
||||
else:
|
||||
mb.user.groups.add("DomainAdmins")
|
||||
mb.user.groups.add(Group.objects.get(name=request.POST["role"]))
|
||||
mb.user.save()
|
||||
ctx = _ctx_ok(reverse(admin.views.permissions))
|
||||
ctx = _ctx_ok(reverse(admin.views.settings))
|
||||
return HttpResponse(simplejson.dumps(ctx),
|
||||
mimetype="application/json")
|
||||
ctx = _ctx_ko("admin/addpermission.html", {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</td>
|
||||
<td>{{ admin.first_name }} {{ admin.last_name }}</td>
|
||||
<td>{{ admin.username }}</td>
|
||||
<td>{{ admin.is_active }}</td>
|
||||
<td>{{ admin.is_active|yesno }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
@@ -33,6 +33,23 @@
|
||||
{% if not domadmins %}
|
||||
<p>{% trans "No domain admin defined." %}</p>
|
||||
{% else %}
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th width="50px">{% trans "Actions" %}</th>
|
||||
<th>{% trans "Domain" %}</th>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Enabled" %}</th>
|
||||
</tr>
|
||||
{% for admin in domadmins %}
|
||||
<tr class="{% cycle 'odd' 'even' %}">
|
||||
<td>
|
||||
<a href=""><img src="/static/pics/remove.png" border="0" title="{% trans 'Remove permission' %}" /></a>
|
||||
</td>
|
||||
<td>{{ admin.domain.name }}</td>
|
||||
<td>{{ admin.first_name }} {{ admin.last_name }}</td>
|
||||
<td>{{ admin.is_active|yesno }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user