aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-10-29 20:11:27 +0300
committerGravatar D0rs4n <[email protected]>2021-12-18 18:02:12 +0100
commitb49612db59ca075f64a4c7da11e3c9ce7e7b19eb (patch)
treef2e6aacdc47282c421fb0d1c03f8644c83114ad4 /pydis_site/apps/api/models
parentAdd validation to filters to not allow duplicates + additional_field -> JSON (diff)
Move filters validations to serializers
Diffstat (limited to 'pydis_site/apps/api/models')
-rw-r--r--pydis_site/apps/api/models/bot/filters.py34
1 files changed, 0 insertions, 34 deletions
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index 472354f8..3a1f3c6a 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -56,11 +56,6 @@ class FilterSettingsMixin(models.Model):
help_text="The duration of the infraction. Null if permanent."
)
- def clean(self):
- """Validate infraction fields as whole."""
- if (self.infraction_duration or self.infraction_reason) and not self.infraction_type:
- raise ValidationError("Infraction type is required if setting infraction duration or reason.")
-
class Meta:
"""Metaclass for settings mixin."""
@@ -113,20 +108,6 @@ class FilterList(FilterSettingsMixin):
allowed_channels = ArrayField(models.IntegerField())
allowed_categories = ArrayField(models.IntegerField())
- def clean(self):
- """Do not allow duplicates in allowed and disallowed lists."""
- # Still run infraction fields validation
- super().clean()
-
- channels_collection = self.allowed_channels + self.disallowed_channels
- categories_collection = self.allowed_categories + self.disallowed_categories
-
- if len(channels_collection) != len(set(channels_collection)):
- raise ValidationError("Allowed and disallowed channels lists contain duplicates.")
-
- if len(categories_collection) != len(set(categories_collection)):
- raise ValidationError("Allowed and disallowed categories lists contain duplicates.")
-
class Meta:
"""Constrain name and list_type unique."""
@@ -181,20 +162,5 @@ class Filter(FilterSettingsMixin):
allowed_channels = ArrayField(models.IntegerField(), null=True)
allowed_categories = ArrayField(models.IntegerField(), null=True)
- def clean(self):
- """Do not allow duplicates in allowed and disallowed lists."""
- # Still run infraction fields validation
- super().clean()
-
- if self.allowed_channels is not None or self.disallowed_channels is not None:
- channels_collection = self.allowed_channels + self.disallowed_channels
- if len(channels_collection) != len(set(channels_collection)):
- raise ValidationError("Allowed and disallowed channels lists contain duplicates.")
-
- if self.allowed_categories is not None or self.disallowed_categories is not None:
- categories_collection = self.allowed_categories + self.disallowed_categories
- if len(categories_collection) != len(set(categories_collection)):
- raise ValidationError("Allowed and disallowed categories lists contain duplicates.")
-
def __str__(self) -> str:
return f"Filter {self.content!r}"