aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-10-28 20:15:36 +0300
committerGravatar D0rs4n <[email protected]>2021-12-18 18:02:12 +0100
commit4c2eaff72ba9e95e1ef8d7b40396187783d87a50 (patch)
tree0efd79857d69eab879a846b6d746c58412c46e63 /pydis_site/apps/api
parentUpdate filters API to actually work (diff)
Add basic validation for infraction fields + use common infraction types
Diffstat (limited to 'pydis_site/apps/api')
-rw-r--r--pydis_site/apps/api/models/bot/filters.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index b9a081e6..eebcf703 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -5,6 +5,8 @@ from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import UniqueConstraint
+from pydis_site.apps.api.models import Infraction
+
class FilterListType(models.IntegerChoices):
"""Choice between allow or deny for a list type."""
@@ -13,16 +15,6 @@ class FilterListType(models.IntegerChoices):
DENY = 0
-class InfractionType(models.TextChoices):
- """Possible type of infractions."""
-
- NOTE = "Note"
- WARN = "Warn"
- MUTE = "Mute"
- KICK = "Kick"
- BAN = "Ban"
-
-
# Valid special values in ping related fields
VALID_PINGS = ("everyone", "here", "moderators", "onduty", "admins")
@@ -49,7 +41,7 @@ class FilterSettingsMixin(models.Model):
help_text="The DM to send to a user triggering this filter."
)
infraction_type = models.CharField(
- choices=InfractionType.choices,
+ choices=Infraction.TYPE_CHOICES,
max_length=4,
null=True,
help_text="The infraction to apply to this user."
@@ -63,6 +55,11 @@ 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."""