mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Added default global values for sending limits.
This commit is contained in:
@@ -116,6 +116,24 @@ class AdminParametersForm(param_forms.AdminParametersForm):
|
||||
)
|
||||
)
|
||||
|
||||
default_domain_quota = forms.IntegerField(
|
||||
label=ugettext_lazy("Default domain quota"),
|
||||
initial=0,
|
||||
help_text=ugettext_lazy(
|
||||
"Default quota (in MB) applied to freshly created domains with no "
|
||||
"value specified. A value of 0 means no quota."
|
||||
)
|
||||
)
|
||||
|
||||
default_domain_message_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Default domain sending limit"),
|
||||
required=False,
|
||||
help_text=ugettext_lazy(
|
||||
"Number of messages freshly created domains will be "
|
||||
"allowed to send per day. Leave empty for no limit."
|
||||
)
|
||||
)
|
||||
|
||||
mbsep = SeparatorField(label=ugettext_lazy("Mailboxes"))
|
||||
|
||||
handle_mailboxes = YesNoField(
|
||||
@@ -135,15 +153,6 @@ class AdminParametersForm(param_forms.AdminParametersForm):
|
||||
)
|
||||
)
|
||||
|
||||
default_domain_quota = forms.IntegerField(
|
||||
label=ugettext_lazy("Default domain quota"),
|
||||
initial=0,
|
||||
help_text=ugettext_lazy(
|
||||
"Default quota (in MB) applied to freshly created domains with no "
|
||||
"value specified. A value of 0 means no quota."
|
||||
)
|
||||
)
|
||||
|
||||
default_mailbox_quota = forms.IntegerField(
|
||||
label=ugettext_lazy("Default mailbox quota"),
|
||||
initial=0,
|
||||
@@ -153,6 +162,15 @@ class AdminParametersForm(param_forms.AdminParametersForm):
|
||||
)
|
||||
)
|
||||
|
||||
default_mailbox_message_limit = forms.IntegerField(
|
||||
label=ugettext_lazy("Default mailbox sending limit"),
|
||||
required=False,
|
||||
help_text=ugettext_lazy(
|
||||
"Number of messages freshly created mailboxes will be "
|
||||
"allowed to send per day. Leave empty for no limit."
|
||||
)
|
||||
)
|
||||
|
||||
auto_account_removal = YesNoField(
|
||||
label=ugettext_lazy("Automatic account removal"),
|
||||
initial=False,
|
||||
|
||||
@@ -272,6 +272,7 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
self.field_widths = {
|
||||
"quota": 3
|
||||
}
|
||||
params = dict(param_tools.get_global_parameters("admin"))
|
||||
if self.mb is not None:
|
||||
self.fields["email"].required = True
|
||||
qset = self.mb.aliasrecipient_set.filter(alias__internal=False)
|
||||
@@ -292,12 +293,14 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
if self.mb.message_limit:
|
||||
self.fields["message_limit"].initial = self.mb.message_limit
|
||||
self.fields["create_alias_with_old_address"].initial = (
|
||||
param_tools.get_global_parameter(
|
||||
"create_alias_on_mbox_rename")
|
||||
params["create_alias_on_mbox_rename"]
|
||||
)
|
||||
else:
|
||||
del self.fields["create_alias_with_old_address"]
|
||||
self.fields["quota_act"].initial = True
|
||||
if params["default_mailbox_message_limit"] is not None:
|
||||
self.fields["message_limit"].initial = (
|
||||
params["default_mailbox_message_limit"])
|
||||
|
||||
if len(args) and isinstance(args[0], QueryDict):
|
||||
self._load_from_qdict(
|
||||
|
||||
@@ -70,6 +70,9 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm):
|
||||
super(DomainFormGeneral, self).__init__(*args, **kwargs)
|
||||
params = dict(param_tools.get_global_parameters("admin"))
|
||||
self.fields["quota"].initial = params["default_domain_quota"]
|
||||
if params["default_domain_message_limit"] is not None:
|
||||
self.fields["message_limit"].initial = (
|
||||
params["default_domain_message_limit"])
|
||||
self.fields["default_mailbox_quota"].initial = (
|
||||
params["default_mailbox_quota"])
|
||||
self.fields["type"].choices = constants.DOMAIN_TYPES
|
||||
|
||||
@@ -86,7 +86,14 @@ class DomainSerializer(serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Set permissions."""
|
||||
params = dict(param_tools.get_global_parameters("admin"))
|
||||
domain = models.Domain(**validated_data)
|
||||
condition = (
|
||||
params["default_domain_message_limit"] is not None and
|
||||
"message_limit" not in validated_data
|
||||
)
|
||||
if condition:
|
||||
domain.message_limit = params["default_domain_message_limit"]
|
||||
creator = self.context["request"].user
|
||||
core_signals.can_create_object.send(
|
||||
sender=self.__class__, context=creator,
|
||||
@@ -327,6 +334,10 @@ class WritableAccountSerializer(AccountSerializer):
|
||||
mb = admin_models.Mailbox(
|
||||
user=account, address=address, domain=domain, **data)
|
||||
mb.set_quota(quota, creator.has_perm("admin.add_domain"))
|
||||
default_msg_limit = param_tools.get_global_parameter(
|
||||
"default_mailbox_message_limit")
|
||||
if default_msg_limit is not None:
|
||||
mb.message_limit = default_msg_limit
|
||||
mb.save(creator=creator)
|
||||
account.email = full_address
|
||||
return mb
|
||||
|
||||
Reference in New Issue
Block a user