mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
wip: Resellers and limits
* A new limit has been added : the maximum number of domain admins a user can create * Code simplification see #105
This commit is contained in:
+20
-21
@@ -295,15 +295,14 @@ class DatesAware(models.Model):
|
||||
ObjectDates.set_for_object(self)
|
||||
super(DatesAware, self).save(*args, **kwargs)
|
||||
|
||||
def __creation(self):
|
||||
@property
|
||||
def creation(self):
|
||||
return self.dates.creation
|
||||
|
||||
def __last_modification(self):
|
||||
@property
|
||||
def last_modification(self):
|
||||
return self.dates.last_modification
|
||||
|
||||
creation = property(__creation)
|
||||
last_modification = property(__last_modification)
|
||||
|
||||
class Domain(DatesAware):
|
||||
name = models.CharField(ugettext_noop('name'), max_length=100, unique=True,
|
||||
help_text=ugettext_noop("The domain name"))
|
||||
@@ -317,14 +316,14 @@ class Domain(DatesAware):
|
||||
("view_domain", "View domain"),
|
||||
("view_domains", "View domains"),
|
||||
)
|
||||
|
||||
def __domainalias_count(self):
|
||||
|
||||
@property
|
||||
def domainalias_count(self):
|
||||
return len(self.domainalias_set.all())
|
||||
domainalias_count = property(__domainalias_count)
|
||||
|
||||
def __mailbox_count(self):
|
||||
@property
|
||||
def mailbox_count(self):
|
||||
return len(self.mailbox_set.all())
|
||||
mailbox_count = property(__mailbox_count)
|
||||
|
||||
def create_dir(self):
|
||||
if parameters.get_admin("CREATE_DIRECTORIES") == "yes":
|
||||
@@ -407,25 +406,25 @@ class Mailbox(DatesAware):
|
||||
self.mdirroot += '/'
|
||||
|
||||
def __str__(self):
|
||||
return self.full_address()
|
||||
return self.full_address
|
||||
|
||||
@property
|
||||
def full_address(self):
|
||||
return "%s@%s" % (self.address, self.domain.name)
|
||||
|
||||
def __enabled(self):
|
||||
@property
|
||||
def enabled(self):
|
||||
return self.user.is_active
|
||||
enabled = property(__enabled)
|
||||
|
||||
def __full_path(self):
|
||||
@property
|
||||
def full_path(self):
|
||||
path = os.path.join(parameters.get_admin("STORAGE_PATH"),
|
||||
self.domain.name, self.address)
|
||||
return os.path.abspath(path)
|
||||
full_path = property(__full_path)
|
||||
|
||||
def __alias_count(self):
|
||||
@property
|
||||
def alias_count(self):
|
||||
return len(self.alias_set.all())
|
||||
alias_count = property(__alias_count)
|
||||
|
||||
def create_dir(self):
|
||||
if parameters.get_admin("CREATE_DIRECTORIES") == "yes":
|
||||
@@ -607,15 +606,15 @@ class Alias(DatesAware):
|
||||
("view_aliases", "View aliases"),
|
||||
)
|
||||
|
||||
def __full_address(self):
|
||||
@property
|
||||
def full_address(self):
|
||||
return "%s@%s" % (self.address, self.domain.name)
|
||||
full_address = property(__full_address)
|
||||
|
||||
def __targets(self):
|
||||
@property
|
||||
def targets(self):
|
||||
ret = "<br/>".join(map(lambda m: str(m), self.mboxes.all()))
|
||||
ret += "<br/>" + self.repr_extmboxes()
|
||||
return ret
|
||||
targets = property(__targets)
|
||||
|
||||
def save(self, int_targets, ext_targets, *args, **kwargs):
|
||||
if len(ext_targets):
|
||||
|
||||
+6
-5
@@ -70,7 +70,7 @@ def _validate_domain(request, form, successmsg, commonctx,
|
||||
@permission_required("admin.add_domain")
|
||||
@transaction.commit_on_success
|
||||
def newdomain(request, tplname="admin/adminform.html"):
|
||||
events.raiseEvent("CanCreateDomain", request.user)
|
||||
events.raiseEvent("CanCreate", request.user, "domains")
|
||||
def newdomain_cb(user, domain):
|
||||
grant_access_to_object(user, domain, is_owner=True)
|
||||
events.raiseEvent("CreateDomain", user, domain)
|
||||
@@ -152,7 +152,7 @@ def domaliases(request):
|
||||
@permission_required("admin.add_domainalias")
|
||||
@transaction.commit_on_success
|
||||
def newdomalias(request, tplname="admin/adminform.html"):
|
||||
events.raiseEvent("CanCreateDomainAlias", request.user)
|
||||
events.raiseEvent("CanCreate", request.user, "domain_aliases")
|
||||
commonctx = {"title" : _("New domain alias"),
|
||||
"submit_label" : _("Create"),
|
||||
"action" : reverse(newdomalias),
|
||||
@@ -275,7 +275,7 @@ def mailboxes_search(request):
|
||||
@permission_required("admin.add_mailbox")
|
||||
@transaction.commit_on_success
|
||||
def newmailbox(request, tplname="admin/adminform.html"):
|
||||
events.raiseEvent("CanCreateMailbox", request.user)
|
||||
events.raiseEvent("CanCreate", request.user, "mailboxes")
|
||||
commonctx = {"title" : _("New mailbox"),
|
||||
"submit_label" : _("Create"),
|
||||
"action" : reverse(newmailbox),
|
||||
@@ -423,7 +423,7 @@ def _validate_mbalias(request, form, successmsg, tplname, commonctx, callback=No
|
||||
@permission_required("admin.add_alias")
|
||||
@transaction.commit_on_success
|
||||
def newmbalias(request, tplname="admin/mbaliasform.html"):
|
||||
events.raiseEvent("CanCreateMailboxAlias", request.user)
|
||||
events.raiseEvent("CanCreate", request.user, "mailbox_aliases")
|
||||
commonctx = {"title" : _("New mailbox alias"),
|
||||
"submit_label" : _("Create"),
|
||||
"action" : reverse(newmbalias),
|
||||
@@ -496,7 +496,7 @@ def permissions(request, tplname='admin/permissions.html'):
|
||||
permtables += [
|
||||
{"id" : "domain_admins",
|
||||
"title" : _("Domain administrators"),
|
||||
"rel" : "350 250",
|
||||
"rel" : "350 100",
|
||||
"content" : DomainAdminsPerms().get(request)}
|
||||
]
|
||||
|
||||
@@ -515,6 +515,7 @@ def add_permission(request):
|
||||
else:
|
||||
pobj = pclass()
|
||||
if request.method == "GET":
|
||||
events.raiseEvent("CanCreate", request.user, role)
|
||||
return pobj.get_add_form(request)
|
||||
status, data = pobj.add(request)
|
||||
if not status:
|
||||
|
||||
Reference in New Issue
Block a user