diff --git a/admin/templatetags/admin_extras.py b/admin/templatetags/admin_extras.py index b228f0089..4f3b9a34f 100644 --- a/admin/templatetags/admin_extras.py +++ b/admin/templatetags/admin_extras.py @@ -141,6 +141,16 @@ def identity_actions(user, iid): ] return render_actions(actions) +@register.simple_tag +def domadmin_actions(daid, domid): + actions = [dict( + name="removeperm", + url=reverse(admin.views.remove_permission) + "?domid=%s&daid=%s" % (domid, daid), + img="icon-trash", + title=_("Remove this permission") + )] + return render_actions(actions) + @register.simple_tag def loadadminextmenu(user): menu = events.raiseQueryEvent("AdminMenuDisplay", "admin_menu_box", user) diff --git a/admin/urls.py b/admin/urls.py index 5586301a2..2251bc5d3 100644 --- a/admin/urls.py +++ b/admin/urls.py @@ -19,6 +19,7 @@ urlpatterns = patterns( (r'^settings/extensions/save/$', 'saveextensions'), (r'^permissions/searchaccount/$', 'search_account'), + (r'^permissions/remove/$', 'remove_permission'), (r'^identities/$', 'identities'), (r'^identities/import/$', 'import_identities'), diff --git a/admin/views.py b/admin/views.py index 6da0a4494..84afbe789 100644 --- a/admin/views.py +++ b/admin/views.py @@ -69,7 +69,7 @@ def _validate_domain(request, form, successmsg, commonctx, tplname, @login_required @permission_required("admin.add_domain") @transaction.commit_on_success -def newdomain(request): +def newdomain(request, tplname="admin/newdomainform.html"): events.raiseEvent("CanCreate", request.user, "domains") def newdomain_cb(user, domain): grant_access_to_object(user, domain, is_owner=True) @@ -83,30 +83,39 @@ def newdomain(request): if request.method == "POST": form = DomainForm(request.POST) return _validate_domain(request, form, _("Domain created"), commonctx, - "admin/domainform.html", - callback=newdomain_cb) + tplname, callback=newdomain_cb) form = DomainForm() commonctx["form"] = form - return _render(request, "common/generic_modal_form.html", commonctx) + return _render(request, tplname, commonctx) @login_required @permission_required("admin.change_domain") -def editdomain(request, dom_id, tplname="admin/domainform.html"): +def editdomain(request, dom_id, tplname="admin/editdomainform.html"): domain = Domain.objects.get(pk=dom_id) if not request.user.can_access(domain): raise PermDeniedException(_("You can't edit this domain")) - commonctx = {"title" : _("Domain editing"), + domadmins = map(lambda oaccess: oaccess.user, domain.owners.all()) + domadmins = filter( + lambda u: request.user.can_access(u) and not u.is_superuser, + domadmins + ) + if not request.user.is_superuser: + domadmins = filter(lambda u: u.group == "DomainAdmins", domadmins) + + commonctx = {"title" : domain.name, "action_label" : _("Update"), "action_classes" : "submit", "action" : reverse(editdomain, args=[dom_id]), - "formid" : "domform"} + "formid" : "domform", + "domain" : domain} if request.method == "POST": form = DomainForm(request.POST, instance=domain) return _validate_domain(request, form, _("Domain modified"), commonctx, tplname) form = DomainForm(instance=domain) commonctx["form"] = form + commonctx["domadmins"] = domadmins return _render(request, tplname, commonctx) @login_required @@ -420,6 +429,23 @@ def search_account(request): result = map(lambda u: u.username, users.all()) return ajax_simple_response(result) +@login_required +@permission_required("admin.add_domain") +def remove_permission(request): + domid = request.GET.get("domid", None) + daid = request.GET.get("daid", None) + if domid is None or daid is None: + raise AdminError(_("Invalid request")) + try: + account = User.objects.get(pk=daid) + domain = Domain.objects.get(pk=domid) + except (User.DoesNotExist, Domain.DoesNotExist): + raise AdminError(_("Invalid request")) + if not request.user.can_access(account) or not request.user.can_access(domain): + raise AdminError(_("Permission denied")) + ungrant_access_to_object(domain, account) + return ajax_simple_response(dict(status="ok")) + @login_required @user_passes_test(lambda u: u.is_superuser) def viewparameters(request, tplname='admin/parameters.html'): diff --git a/extensions/webmail/static/js/webmail.js b/extensions/webmail/static/js/webmail.js index 988649142..209cdb62f 100644 --- a/extensions/webmail/static/js/webmail.js +++ b/extensions/webmail/static/js/webmail.js @@ -165,6 +165,14 @@ Webmail.prototype = { }); }, + go_back_to_listing: function() { + var curmb = this.get_current_mailbox(); + this.navobject.delparam("mailid").delparam("mbox") + .setparams({action: "listmailbox", mbox: curmb}); + this.restore_nav_params(); + this.navobject.update(); + }, + /* * Enable or disable edit and remove actions for the currently * selected mailbox. @@ -838,11 +846,7 @@ Webmail.prototype = { $("#listing").css("overflow", "hidden"); $("a[name=close]").click($.proxy(function(e) { e.preventDefault(); - var curmb = this.get_current_mailbox(); - this.navobject.delparam("mailid").delparam("mbox") - .setparams({action: "listmailbox", mbox: curmb}); - this.restore_nav_params(); - this.navobject.update(); + this.go_back_to_listing(); }, this)); }, @@ -863,7 +867,7 @@ Webmail.prototype = { delete_callback: function(data) { if (data.status == "ok") { - history.go(-2); + this.go_back_to_listing(); $("body").notify("success", gettext("Message deleted"), 2000); } else { $("body").notify("error", data.respmsg); diff --git a/static/css/admin.css b/static/css/admin.css index 9f3729324..823c6087f 100644 --- a/static/css/admin.css +++ b/static/css/admin.css @@ -2,3 +2,25 @@ text-align: center; margin-bottom: 10px; } + +span.title { + margin-left: 40px; + margin-bottom: 10px; + float: left; + font-weight: bold; + width: 180px; +} + +table#domadmins th#actions { + text-align: right; +} + +table#domadmins td[name="actions"] { + text-align: right; +} + +.search { + width: 85%; + -webkit-border-radius:14px;-moz-border-radius:14px;border-radius:14px; + padding-left: 14px; +} \ No newline at end of file diff --git a/static/js/admin.js b/static/js/admin.js index 464ae1be9..f45ab9df9 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -7,6 +7,18 @@ function domainform_cb() { error_cb: domainform_cb }); }); + $("a[name=removeperm]").click(function(e) { + var $tr = $(this).parent().parent(); + simple_ajax_request.apply(this, [e, { + ok_cb: function(resp) { + $tr.remove(); + if (!$("#domadmins").children("tr").length) { + $("#admins").html('
' + + gettext("No domain administrator defined") + "
"); + } + } + }]); + }); } function accountform_init() { diff --git a/static/js/global.js b/static/js/global.js index c6a216864..7809d78f3 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -186,15 +186,21 @@ function get_target(e, tag) { /* * Send a simple AJAX request. */ -function simple_ajax_request(e) { +function simple_ajax_request(e, uoptions) { var $this = $(this); - e.preventDefault(); + var defaults = {}; + var options = $.extend({}, defaults, uoptions); + + if (e != undefined) e.preventDefault(); $.ajax({ url: $this.attr("href"), dataType: 'json', success: function(data) { if (data.status == "ok") { - $("body").notify("success", data.respmsg, 2000); + if (options.ok_cb) options.ok_cb(data); + if (options.respmsg) { + $("body").notify("success", data.respmsg, 2000); + } } else { $("body").notify("error", data.respmsg); } diff --git a/templates/admin/editdomainform.html b/templates/admin/editdomainform.html new file mode 100644 index 000000000..137140311 --- /dev/null +++ b/templates/admin/editdomainform.html @@ -0,0 +1,31 @@ +{% extends "common/generic_modal.html" %}{% load i18n libextras admin_extras %} +{% block modalbody %} + +
+
+ {% if error %}
{{ error }}
{% endif %} +
+ {% render_field form.name %} + {% render_field form.quota %} + {% render_fields_group form "aliases" %} + {% render_field form.enabled %} +
+
+
{% if domadmins %} + + + {% for da in domadmins %} + + {% endfor %} +
{% trans "Username" %}{% trans "Name" %}
{{ da.username }}{{ da.fullname }}{% domadmin_actions da.id domain.id %}
{% else %}
{% trans "No domain administrator defined" %}
{% endif %} +
+
+
{% trans "Creation date" %}{{ domain.creation }}
+
{% trans "Last modification date" %}{{ domain.last_modification }}
+
+
+{% endblock %} diff --git a/templates/admin/domainform.html b/templates/admin/newdomainform.html similarity index 62% rename from templates/admin/domainform.html rename to templates/admin/newdomainform.html index f305a8ee1..83346e5b7 100644 --- a/templates/admin/domainform.html +++ b/templates/admin/newdomainform.html @@ -1,6 +1,4 @@ -{% extends "common/generic_modal_form.html" %} -{% load libextras %} -{% block formbody %} +{% extends "common/generic_modal_form.html" %}{% load libextras %}{% block formbody %} {% render_field form.name %} {% render_field form.quota %} {% render_fields_group form "aliases" %} diff --git a/templates/admin/searchform.html b/templates/admin/searchform.html index 8bb8d7f95..0c6773099 100644 --- a/templates/admin/searchform.html +++ b/templates/admin/searchform.html @@ -1,6 +1,6 @@ {% load i18n %} -