mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user