mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
wip: UI refactoring
* Activate by default the 'simple user' mode for domain administrators (when creating a new accoun) * Don't forget to grant access to objects created by domain admins to super admins see #204
This commit is contained in:
+1
-1
@@ -202,7 +202,7 @@ class User(DUser):
|
||||
|
||||
def get_identities(self):
|
||||
from modoboa.lib.permissions import get_content_type
|
||||
|
||||
|
||||
userct = get_content_type(self)
|
||||
alct = get_content_type(Alias)
|
||||
return self.objectaccess_set.filter(content_type__in=[userct, alct])
|
||||
|
||||
+10
-3
@@ -40,6 +40,9 @@ def grant_access_to_object(user, obj, is_owner=False):
|
||||
* He is the owner (he's just created the object)
|
||||
* He is going to administrate the object (but he is not the owner)
|
||||
|
||||
If the user isn't a *super user* but is the owner, we also grant
|
||||
access to this object to all super admins.
|
||||
|
||||
:param user: a ``User`` object
|
||||
:param obj: an admin. object (Domain, Mailbox, ...)
|
||||
:param is_owner: the user is the unique object's owner
|
||||
@@ -55,9 +58,13 @@ def grant_access_to_object(user, obj, is_owner=False):
|
||||
return
|
||||
|
||||
try:
|
||||
objaccess = ObjectAccess(user=user, content_type=ct,
|
||||
object_id=obj.id, is_owner=is_owner)
|
||||
objaccess.save()
|
||||
ObjectAccess.objects.create(user=user, content_type=ct,
|
||||
object_id=obj.id, is_owner=is_owner)
|
||||
if is_owner and not user.is_superuser:
|
||||
from modoboa.admin.models import User
|
||||
for su in User.objects.filter(is_superuser=True):
|
||||
ObjectAccess.objects.create(user=su, content_type=ct, object_id=obj.id)
|
||||
|
||||
except IntegrityError, e:
|
||||
raise ModoboaException(_("Failed to grant access (%s)" % str(e)))
|
||||
|
||||
|
||||
+24
-12
@@ -21,20 +21,28 @@ function domainform_cb() {
|
||||
});
|
||||
}
|
||||
|
||||
function simpleuser_mode() {
|
||||
$("#id_username").autocompleter({
|
||||
from_character: "@",
|
||||
choices: get_domains_list
|
||||
});
|
||||
$("#id_email").addClass("disabled")
|
||||
.attr("readonly", "")
|
||||
.autocompleter("unbind");
|
||||
}
|
||||
|
||||
function normal_mode() {
|
||||
$("#id_email").removeClass("disabled")
|
||||
.attr("readonly", null)
|
||||
.autocompleter("listen");
|
||||
}
|
||||
|
||||
function generalform_init() {
|
||||
$("#id_role").change(function(e) {
|
||||
if ($(this).attr("value") == "SimpleUsers") {
|
||||
$("#id_username").autocompleter({
|
||||
from_character: "@",
|
||||
choices: get_domains_list
|
||||
});
|
||||
$("#id_email").addClass("disabled")
|
||||
.attr("readonly", "")
|
||||
.autocompleter("unbind");
|
||||
simpleuser_mode();
|
||||
} else {
|
||||
$("#id_email").removeClass("disabled")
|
||||
.attr("readonly", null)
|
||||
.autocompleter("listen");
|
||||
normal_mode();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -45,7 +53,11 @@ function mailform_init() {
|
||||
from_character: "@",
|
||||
choices: get_domains_list
|
||||
});
|
||||
$("#id_role").trigger("change");
|
||||
if ($("#id_role").length) {
|
||||
$("#id_role").trigger("change");
|
||||
} else {
|
||||
simpleuser_mode();
|
||||
}
|
||||
$("#id_domains")
|
||||
.autocompleter({
|
||||
choices: get_domains_list
|
||||
@@ -60,7 +72,7 @@ function accountform_init() {
|
||||
}
|
||||
|
||||
function mailform_prefill() {
|
||||
if ($("#id_role").attr("value") == "SimpleUsers") {
|
||||
if (!$("#id_role").length || $("#id_role").attr("value") == "SimpleUsers") {
|
||||
$("#id_email").attr("value", $("#id_username").attr("value"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user