aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-10-28 20:38:59 +0300
committerGravatar D0rs4n <[email protected]>2021-12-18 18:02:12 +0100
commitf4152448dfa4cd9912c22134af01fe37f0b153f6 (patch)
tree5557a2f4ae492c713e399f151ab0d0704d8d4a33 /pydis_site/apps/api
parentAdd validation to filters to not allow duplicated channels and categories (diff)
Add validation to filters to not allow duplicates + additional_field -> JSON
Diffstat (limited to 'pydis_site/apps/api')
-rw-r--r--pydis_site/apps/api/migrations/0070_new_filter_schema.py6
-rw-r--r--pydis_site/apps/api/models/bot/filters.py9
2 files changed, 8 insertions, 7 deletions
diff --git a/pydis_site/apps/api/migrations/0070_new_filter_schema.py b/pydis_site/apps/api/migrations/0070_new_filter_schema.py
index a595bda2..8716cbad 100644
--- a/pydis_site/apps/api/migrations/0070_new_filter_schema.py
+++ b/pydis_site/apps/api/migrations/0070_new_filter_schema.py
@@ -79,7 +79,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.CharField(help_text='The definition of this filter.', max_length=100)),
('description', models.CharField(help_text='Why this filter has been added.', max_length=200)),
- ('additional_field', models.BooleanField(help_text='Implementation specific field.', null=True)),
+ ('additional_field', django.contrib.postgres.fields.jsonb.JSONField(help_text='Implementation specific field.', null=True)),
('ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=20), help_text='Who to ping when this filter triggers.', size=None, validators=[pydis_site.apps.api.models.bot.filters.validate_ping_field], null=True)),
('filter_dm', models.BooleanField(help_text='Whether DMs should be filtered.', null=True)),
('dm_ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=20), help_text='Who to ping when this filter triggers on a DM.', size=None, validators=[pydis_site.apps.api.models.bot.filters.validate_ping_field], null=True)),
@@ -87,7 +87,7 @@ class Migration(migrations.Migration):
('bypass_roles', django.contrib.postgres.fields.ArrayField(base_field=models.BigIntegerField(), help_text='Roles and users who can bypass this filter.', size=None, null=True)),
('enabled', models.BooleanField(help_text='Whether this filter is currently enabled.', null=True)),
('dm_content', models.CharField(help_text='The DM to send to a user triggering this filter.', max_length=1000, null=True)),
- ('infraction_type', models.CharField(choices=[('Note', 'Note'), ('Warn', 'Warn'), ('Mute', 'Mute'), ('Kick', 'Kick'), ('Ban', 'Ban')], help_text='The infraction to apply to this user.', max_length=4, null=True)),
+ ('infraction_type', models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('watch', 'Watch'), ('mute', 'Mute'), ('kick', 'Kick'), ('ban', 'Ban'), ('superstar', 'Superstar'), ('voice_ban', 'Voice Ban')], help_text='The infraction to apply to this user.', max_length=9, null=True)),
('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000)),
('infraction_duration', models.DurationField(help_text='The duration of the infraction. Null if permanent.', null=True)),
('disallowed_channels', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None)),
@@ -109,7 +109,7 @@ class Migration(migrations.Migration):
('bypass_roles', django.contrib.postgres.fields.ArrayField(base_field=models.BigIntegerField(), help_text='Roles and users who can bypass this filter.', size=None)),
('enabled', models.BooleanField(help_text='Whether this filter is currently enabled.')),
('dm_content', models.CharField(help_text='The DM to send to a user triggering this filter.', max_length=1000, null=True)),
- ('infraction_type', models.CharField(choices=[('Note', 'Note'), ('Warn', 'Warn'), ('Mute', 'Mute'), ('Kick', 'Kick'), ('Ban', 'Ban')], help_text='The infraction to apply to this user.', max_length=4, null=True)),
+ ('infraction_type', models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('watch', 'Watch'), ('mute', 'Mute'), ('kick', 'Kick'), ('ban', 'Ban'), ('superstar', 'Superstar'), ('voice_ban', 'Voice Ban')], help_text='The infraction to apply to this user.', max_length=9, null=True)),
('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000)),
('infraction_duration', models.DurationField(help_text='The duration of the infraction. Null if permanent.', null=True)),
('disallowed_channels', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), size=None)),
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index 45dea2c4..472354f8 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -1,11 +1,12 @@
from typing import List
-from django.contrib.postgres.fields import ArrayField
+from django.contrib.postgres.fields import ArrayField, JSONField
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
+# Must be imported that way to avoid circular imports
+from .infraction import Infraction
class FilterListType(models.IntegerChoices):
@@ -42,7 +43,7 @@ class FilterSettingsMixin(models.Model):
)
infraction_type = models.CharField(
choices=Infraction.TYPE_CHOICES,
- max_length=4,
+ max_length=9,
null=True,
help_text="The infraction to apply to this user."
)
@@ -142,7 +143,7 @@ class Filter(FilterSettingsMixin):
content = models.CharField(max_length=100, help_text="The definition of this filter.")
description = models.CharField(max_length=200, help_text="Why this filter has been added.")
- additional_field = models.BooleanField(null=True, help_text="Implementation specific field.")
+ additional_field = JSONField(null=True, help_text="Implementation specific field.")
filter_list = models.ForeignKey(
FilterList, models.CASCADE, related_name="filters",
help_text="The filter list containing this filter."