From 6cfd76809f0e9006b4fdf5163c79e8c91b89102a Mon Sep 17 00:00:00 2001 From: tonio Date: Mon, 6 Apr 2009 18:14:20 +0200 Subject: [PATCH] Some work about permissions. Not finished yet... --- admin/forms.py | 7 ++++++ admin/models.py | 3 +++ admin/urls.py | 1 + admin/views.py | 15 +++++++++++-- locale/fr/LC_MESSAGES/django.po | 2 +- static/js/form.js | 6 +++++ static/js/settings.js | 6 +++++ static/stylesheets/basic.css | 8 +++++++ templates/admin/addpermission.html | 19 ++++++++++++++++ templates/admin/permissions.html | 33 ++++++++++++++++++++++++++++ templates/admin/settings_header.html | 1 + templates/admin/settings_menu.html | 8 +++++++ 12 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 static/js/settings.js create mode 100644 templates/admin/addpermission.html diff --git a/admin/forms.py b/admin/forms.py index 9623af164..07c6771fe 100644 --- a/admin/forms.py +++ b/admin/forms.py @@ -36,3 +36,10 @@ class AliasForm(forms.ModelForm): model = Alias fields = ('address', 'mbox', 'enabled') +class PermissionForm(forms.Form): + domain = forms.ModelChoiceField(queryset=Domain.objects.all(), label=_("Domain"), + required=True) + user = forms.ChoiceField(label=_("User"), required=True) + role = forms.ChoiceField(label=_("Role"), required=True, + choices=(("SuperAdmin", _("Super administrator")), + ("DomainAdmin", _("Domain administrator")))) diff --git a/admin/models.py b/admin/models.py index 7d03fc77f..cfe48be91 100644 --- a/admin/models.py +++ b/admin/models.py @@ -39,6 +39,9 @@ class Domain(models.Model): return False return True + def __str__(self): + return self.name + class Mailbox(models.Model): name = models.CharField(_('name'), max_length=100) address = models.CharField(_('address'), max_length=100) diff --git a/admin/urls.py b/admin/urls.py index b33fc9c26..8e4d4c8bb 100644 --- a/admin/urls.py +++ b/admin/urls.py @@ -16,4 +16,5 @@ urlpatterns = patterns('mailng.admin.views', url(r'^domains/(?P\d+)/aliases/(?P\d+)/$', "aliases", name="mbox-aliases"), (r'^domains/(?P\d+)/delalias/(?P\d+)/$', 'delalias'), (r'^settings/$', 'settings'), + (r'^settings/addperm/$', 'addpermission') ) diff --git a/admin/views.py b/admin/views.py index 097a1d659..9e41d624b 100644 --- a/admin/views.py +++ b/admin/views.py @@ -10,7 +10,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from mailng import admin from mailng.admin.models import Domain, Mailbox, Alias -from forms import MailboxForm, DomainForm, AliasForm +from forms import MailboxForm, DomainForm, AliasForm, PermissionForm import md5 def _ctx_ok(url): @@ -280,4 +280,15 @@ def delalias(request, dom_id, alias_id): @login_required def settings(request): - return _render(request, 'admin/permissions.html', {}) + admins = User.objects.filter(is_superuser=True) + domadmins = User.objects.filter(groups__name="DomainAdmins") + return _render(request, 'admin/permissions.html', { + "admins" : admins, "domadmins" : domadmins + }) + +@login_required +def addpermission(request): + form = PermissionForm() + return _render(request, 'admin/addpermission.html', { + "form" : form + }) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 5757cdea9..0198a9c7e 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -146,7 +146,7 @@ msgstr "Domaines disponibles" #: templates/admin/domains.html:13 msgid "No domain defined." -msgstr "Aucun alias défini." +msgstr "Aucun domaine défini." #: templates/admin/domains.html:18 templates/admin/mailboxes.html:15 msgid "Name" diff --git a/static/js/form.js b/static/js/form.js index 2d9f2b43b..b276b79bd 100644 --- a/static/js/form.js +++ b/static/js/form.js @@ -37,4 +37,10 @@ window.addEvent("domready", function() { if ($("aliasform")) $("aliasform").addEvent("submit", alias_submit); + + if ($("permform")) { + $("id_domain").addEvent("change", function(event) { + + }); + } }); diff --git a/static/js/settings.js b/static/js/settings.js new file mode 100644 index 000000000..fc6ff91ed --- /dev/null +++ b/static/js/settings.js @@ -0,0 +1,6 @@ +window.addEvent('domready', function() { + SqueezeBox.assign($$('a.boxed'), { + parse: 'rel', + + }); +}); \ No newline at end of file diff --git a/static/stylesheets/basic.css b/static/stylesheets/basic.css index 3631acf52..2b14c7c85 100644 --- a/static/stylesheets/basic.css +++ b/static/stylesheets/basic.css @@ -254,6 +254,10 @@ body { width: 90%; } +#setcontent { + margin: 0px auto; + width: 90%; +} .button { margin-left: 35px; @@ -272,4 +276,8 @@ body { .header h1 { font-size: medium; +} + +#setcontent h4 { + margin-top: 0; } \ No newline at end of file diff --git a/templates/admin/addpermission.html b/templates/admin/addpermission.html new file mode 100644 index 000000000..47f19743c --- /dev/null +++ b/templates/admin/addpermission.html @@ -0,0 +1,19 @@ +{% extends "admin/layout_simple.html" %} +{% load i18n %} +{% block html_head %} + +{% endblock %} +{% block content %} +

{% trans "Add permission" %}

+ +{% if error %}
{{ error }}
{% endif %} +{% url admin.views.add_permission as addperm_url %} +
+ {% include "admin/genericform.html" %} +
+ +
+ +
+
+{% endblock %} diff --git a/templates/admin/permissions.html b/templates/admin/permissions.html index f2453ce18..0a9d10c4d 100644 --- a/templates/admin/permissions.html +++ b/templates/admin/permissions.html @@ -2,4 +2,37 @@ {% block menu %} {% load admin_extras %} {% settings_menu "permissions" %} +{% endblock %} +{% block setcontent %} +{% load i18n %} +{% if not admins %} +

{% trans "No superuser defined?!" %}

+{% else %} +

Super admins

+ + + + + + + + {% for admin in admins %} + + + + + + + {% endfor %} +
{% trans "Actions" %}{% trans "Full name" %}{% trans "User name" %}{% trans "Enabled" %}
+ + {{ admin.first_name }} {{ admin.last_name }}{{ admin.username }}{{ admin.is_active }}
+

+{% endif %} +

Domain admins

+{% if not domadmins %} +

{% trans "No domain admin defined." %}

+{% else %} + +{% endif %} {% endblock %} \ No newline at end of file diff --git a/templates/admin/settings_header.html b/templates/admin/settings_header.html index 6e6ed95d7..6ea4363da 100644 --- a/templates/admin/settings_header.html +++ b/templates/admin/settings_header.html @@ -1,5 +1,6 @@ {% extends "admin/layout.html" %} {% block html_head %} + {% endblock %} {% block mainframe %} {% load i18n %} diff --git a/templates/admin/settings_menu.html b/templates/admin/settings_menu.html index 842b48141..5463b8fd3 100644 --- a/templates/admin/settings_menu.html +++ b/templates/admin/settings_menu.html @@ -7,4 +7,12 @@ {% trans "Permissions" %} + {% url admin.views.addpermission as addperm_url %} +
  • + + + {% trans "Add permission" %} + +