mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -9,7 +9,7 @@ from django.db import IntegrityError
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from modoboa.lib import events
|
||||
from modoboa.lib import events, parameters
|
||||
from modoboa.extensions import ModoExtension, exts_pool
|
||||
from models import *
|
||||
from forms import ResourcePoolForm
|
||||
@@ -49,7 +49,12 @@ class Limits(ModoExtension):
|
||||
except IntegrityError:
|
||||
pass
|
||||
|
||||
def load(self):
|
||||
from app_settings import ParametersForm
|
||||
parameters.register(ParametersForm, _("Limits"))
|
||||
|
||||
def destroy(self):
|
||||
parameters.unregister()
|
||||
Group.objects.get(name="Resellers").delete()
|
||||
|
||||
exts_pool.register_extension(Limits)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from modoboa.lib.parameters import AdminParametersForm
|
||||
from modoboa.lib.formutils import SeparatorField
|
||||
|
||||
|
||||
class ParametersForm(AdminParametersForm):
|
||||
app = "limits"
|
||||
|
||||
defv_sep = SeparatorField(label=_("Default limits"))
|
||||
|
||||
deflt_domain_admins_limit = forms.IntegerField(
|
||||
label=_("Domain admins"),
|
||||
initial=0,
|
||||
help_text=_("Maximum number of allowed domain administrators for a new administrator"),
|
||||
widget=forms.widgets.TextInput(attrs={"class": "span1"})
|
||||
)
|
||||
deflt_domains_limit = forms.IntegerField(
|
||||
label=_("Domains"),
|
||||
initial=0,
|
||||
help_text=_("Maximum number of allowed domains for a new administrator"),
|
||||
widget=forms.widgets.TextInput(attrs={"class": "span1"})
|
||||
)
|
||||
deflt_domain_aliases_limit = forms.IntegerField(
|
||||
label=_("Domain aliases"),
|
||||
initial=0,
|
||||
help_text=_("Maximum number of allowed domain aliases for a new administrator"),
|
||||
widget=forms.widgets.TextInput(attrs={"class": "span1"})
|
||||
)
|
||||
deflt_mailboxes_limit = forms.IntegerField(
|
||||
label=_("Mailboxes"),
|
||||
initial=0,
|
||||
help_text=_("Maximum number of allowed mailboxes for a new administrator"),
|
||||
widget=forms.widgets.TextInput(attrs={"class": "span1"})
|
||||
)
|
||||
deflt_mailbox_aliases_limit = forms.IntegerField(
|
||||
label=_("Mailbox aliases"),
|
||||
initial=0,
|
||||
help_text=_("Maximum number of allowed aliases for a new administrator"),
|
||||
widget=forms.widgets.TextInput(attrs={"class": "span1"})
|
||||
)
|
||||
@@ -123,8 +123,7 @@ def create_pool(user):
|
||||
check_limit(owner, 'domain_admins_limit')
|
||||
inc_limit(owner, 'domain_admins_limit')
|
||||
|
||||
if user.belongs_to_group("DomainAdmins") or \
|
||||
user.belongs_to_group("Resellers"):
|
||||
if user.group in ["DomainAdmins", "Resellers"]:
|
||||
p = LimitsPool(user=user)
|
||||
p.save()
|
||||
p.create_limits()
|
||||
|
||||
@@ -2,26 +2,35 @@
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.auth.models import User, Group
|
||||
from modoboa.lib import parameters
|
||||
from models import *
|
||||
from lib import *
|
||||
|
||||
|
||||
class ResourcePoolForm(forms.Form):
|
||||
domain_admins_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Domain admins"),
|
||||
help_text=ugettext_lazy("Maximum number of domain administrators this user can create")
|
||||
)
|
||||
domains_limit = forms.IntegerField(label=ugettext_lazy("Domains"),
|
||||
help_text=ugettext_lazy("Maximum number of domains this user can create"))
|
||||
domain_aliases_limit = forms.IntegerField(label=ugettext_lazy("Domain aliases"),
|
||||
help_text=ugettext_lazy("Maximum number of domain aliases this user can create"))
|
||||
mailboxes_limit = forms.IntegerField(label=ugettext_lazy("Mailboxes"),
|
||||
help_text=ugettext_lazy("Maximum number of mailboxes this user can create"))
|
||||
mailbox_aliases_limit = forms.IntegerField(label=ugettext_lazy("Mailbox aliases"),
|
||||
help_text=ugettext_lazy("Maximum number of mailbox aliases this user can create"))
|
||||
)
|
||||
domains_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Domains"),
|
||||
help_text=ugettext_lazy("Maximum number of domains this user can create")
|
||||
)
|
||||
domain_aliases_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Domain aliases"),
|
||||
help_text=ugettext_lazy("Maximum number of domain aliases this user can create")
|
||||
)
|
||||
mailboxes_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Mailboxes"),
|
||||
help_text=ugettext_lazy("Maximum number of mailboxes this user can create")
|
||||
)
|
||||
mailbox_aliases_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Mailbox aliases"),
|
||||
help_text=ugettext_lazy("Maximum number of mailbox aliases this user can create")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if kwargs.has_key("instance"):
|
||||
if "instance" in kwargs:
|
||||
self.account = kwargs["instance"]
|
||||
del kwargs["instance"]
|
||||
super(ResourcePoolForm, self).__init__(*args, **kwargs)
|
||||
@@ -51,9 +60,13 @@ class ResourcePoolForm(forms.Form):
|
||||
|
||||
def load_from_user(self, user):
|
||||
for l in limits_tpl:
|
||||
if not self.fields.has_key(l[0]):
|
||||
if not l[0] in self.fields:
|
||||
continue
|
||||
self.fields[l[0]].initial = user.limitspool.getmaxvalue(l[0])
|
||||
# The following lines will become useless in a near
|
||||
# future.
|
||||
if self.fields[l[0]].initial == -2:
|
||||
self.fields[l[0]].initial = parameters.get_admin("DEFLT_%s" % l[0].upper())
|
||||
|
||||
def allocate_from_pool(self, limit, pool):
|
||||
ol = pool.get_limit(limit.name)
|
||||
@@ -61,7 +74,9 @@ class ResourcePoolForm(forms.Form):
|
||||
raise BadLimitValue(_("Your resources are not initialized yet"))
|
||||
newvalue = self.cleaned_data[limit.name]
|
||||
if newvalue == -1 and ol.maxvalue != -1:
|
||||
raise BadLimitValue(_("You're not allowed to define unlimited values"))
|
||||
raise BadLimitValue(
|
||||
_("You're not allowed to define unlimited values")
|
||||
)
|
||||
|
||||
if limit.maxvalue > -1:
|
||||
newvalue -= limit.maxvalue
|
||||
@@ -69,7 +84,7 @@ class ResourcePoolForm(forms.Form):
|
||||
return
|
||||
remain = ol.maxvalue - ol.curvalue
|
||||
if newvalue > remain:
|
||||
raise UnsifficientResource(ol)
|
||||
raise UnsufficientResource(ol)
|
||||
ol.maxvalue -= newvalue
|
||||
ol.save()
|
||||
|
||||
@@ -78,12 +93,10 @@ class ResourcePoolForm(forms.Form):
|
||||
|
||||
owner = get_object_owner(self.account)
|
||||
for ltpl in limits_tpl:
|
||||
if not self.cleaned_data.has_key(ltpl[0]):
|
||||
if not ltpl[0] in self.cleaned_data:
|
||||
continue
|
||||
l = self.account.limitspool.limit_set.get(name=ltpl[0])
|
||||
if not owner.is_superuser:
|
||||
self.allocate_from_pool(l, owner.limitspool)
|
||||
l.maxvalue = self.cleaned_data[ltpl[0]]
|
||||
l.save()
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class LimitReached(ModoboaException):
|
||||
def __str__(self):
|
||||
return _("%s: limit reached") % self.limit.label
|
||||
|
||||
class UnsifficientResource(ModoboaException):
|
||||
class UnsufficientResource(ModoboaException):
|
||||
def __init__(self, limit):
|
||||
self.limit = limit
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.admin.models import User
|
||||
from django.conf import settings
|
||||
|
||||
@@ -22,6 +23,7 @@ class LimitsPool(models.Model):
|
||||
l = Limit()
|
||||
l.name = ltpl[0]
|
||||
l.pool = self
|
||||
l.maxvalue = int(parameters.get_admin("DEFLT_%s" % ltpl[0].upper()))
|
||||
l.save()
|
||||
|
||||
def getcurvalue(self, lname):
|
||||
|
||||
Reference in New Issue
Block a user