Default mailbox quota should not be greater than quota.

see #1035
This commit is contained in:
Antoine Nguyen
2017-02-20 16:57:38 +01:00
parent c677de4e17
commit 6ecb50deab
3 changed files with 23 additions and 0 deletions
+7
View File
@@ -96,6 +96,13 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm):
"name", _("A %s with this name already exists")
% unicode(label)
)
condition = (
self.cleaned_data["default_mailbox_quota"] >
self.cleaned_data["quota"])
if condition:
self.add_error(
"default_mailbox_quota",
_("Cannot be greater than domain quota"))
if self.user.role == "Resellers":
limit = self.user.userobjectlimit_set.get(name="quota")
if limit.max_value != 0:
+5
View File
@@ -265,6 +265,11 @@ class Domain(AdminObject):
_("Invalid default mailbox quota value for domain '{}'")
.format(self.name)
)
if self.quota != 0 and self.default_mailbox_quota > self.quota:
raise BadRequest(
_("Default mailbox quota cannot be greater than domain "
"quota")
)
self.enabled = (row[4].strip() in ["True", "1", "yes", "y"])
core_signals.can_create_object.send(
sender=self.__class__, context=user, klass=Domain,
+11
View File
@@ -27,6 +27,17 @@ class DomainSerializer(serializers.ModelSerializer):
"pk", "name", "quota", "default_mailbox_quota", "enabled", "type",
)
def validate(self, data):
"""Check quota values."""
quota = data["quota"]
default_mailbox_quota = data["default_mailbox_quota"]
if quota != 0 and default_mailbox_quota > quota:
raise serializers.ValidationError({
"default_mailbox_quota":
_("Cannot be greater than domain quota")
})
return data
def create(self, validated_data):
"""Set permissions."""
domain = models.Domain(**validated_data)