aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2022-10-08 15:44:37 +0300
committerGravatar mbaruh <[email protected]>2022-10-10 22:33:42 +0300
commitc3747b6d09ff968858eab698eb5fcffb9c3fbd1f (patch)
tree1d7b5a872d113100ff2d26166eb340ed9eb5e6b2 /pydis_site/apps/api
parentAllow ping arrays to be empty (diff)
Allow char fields to be blank
This is necessary allow filters to define a blank message when the default is not blank. Additionally allows bypass_roles to be empty like the other array fields
Diffstat (limited to 'pydis_site/apps/api')
-rw-r--r--pydis_site/apps/api/migrations/0085_new_filter_schema.py12
-rw-r--r--pydis_site/apps/api/models/bot/filters.py5
-rw-r--r--pydis_site/apps/api/serializers.py12
3 files changed, 21 insertions, 8 deletions
diff --git a/pydis_site/apps/api/migrations/0085_new_filter_schema.py b/pydis_site/apps/api/migrations/0085_new_filter_schema.py
index 2e721df4..a38194ef 100644
--- a/pydis_site/apps/api/migrations/0085_new_filter_schema.py
+++ b/pydis_site/apps/api/migrations/0085_new_filter_schema.py
@@ -108,10 +108,10 @@ class Migration(migrations.Migration):
('delete_messages', models.BooleanField(help_text='Whether this filter should delete messages triggering it.', null=True)),
('bypass_roles', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), 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)),
- ('dm_embed', models.CharField(help_text='The content of the DM embed', max_length=2000, null=True)),
+ ('dm_content', models.CharField(help_text='The DM to send to a user triggering this filter.', max_length=1000, null=True, blank=True)),
+ ('dm_embed', models.CharField(help_text='The content of the DM embed', max_length=2000, null=True, blank=True)),
('infraction_type', models.CharField(choices=[('NOTE', 'Note'), ('WARNING', 'Warning'), ('WATCH', 'Watch'), ('MUTE', 'Mute'), ('KICK', 'Kick'), ('BAN', 'Ban'), ('SUPERSTAR', 'Superstar'), ('VOICE_BAN', 'Voice Ban'), ('VOICE_MUTE', 'Voice Mute')], help_text='The infraction to apply to this user.', max_length=10, null=True)),
- ('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000, null=True)),
+ ('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000, null=True, blank=True)),
('infraction_duration', models.DurationField(help_text='The duration of the infraction. Null if permanent.', null=True)),
('infraction_channel', models.BigIntegerField(validators=(MinValueValidator(limit_value=0, message="Channel IDs cannot be negative."),), help_text="Channel in which to send the infraction.", null=True)),
('disabled_channels', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Channels in which to not run the filter.", null=True, size=None)),
@@ -133,10 +133,10 @@ class Migration(migrations.Migration):
('delete_messages', models.BooleanField(help_text='Whether this filter should delete messages triggering it.')),
('bypass_roles', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), 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)),
- ('dm_embed', models.CharField(help_text='The content of the DM embed', max_length=2000, null=True)),
+ ('dm_content', models.CharField(help_text='The DM to send to a user triggering this filter.', max_length=1000, null=True, blank=True)),
+ ('dm_embed', models.CharField(help_text='The content of the DM embed', max_length=2000, null=True, blank=True)),
('infraction_type', models.CharField(choices=[('NOTE', 'Note'), ('WARNING', 'Warning'), ('WATCH', 'Watch'), ('MUTE', 'Mute'), ('KICK', 'Kick'), ('BAN', 'Ban'), ('SUPERSTAR', 'Superstar'), ('VOICE_BAN', 'Voice Ban'), ('VOICE_MUTE', 'Voice Mute')], help_text='The infraction to apply to this user.', max_length=10, null=True)),
- ('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000, null=True)),
+ ('infraction_reason', models.CharField(help_text='The reason to give for the infraction.', max_length=1000, null=True, blank=True)),
('infraction_duration', models.DurationField(help_text='The duration of the infraction. Null if permanent.', null=True)),
('infraction_channel', models.BigIntegerField(validators=(MinValueValidator(limit_value=0, message="Channel IDs cannot be negative."),), help_text="Channel in which to send the infraction.", null=True)),
('disabled_channels', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Channels in which to not run the filter.", size=None)),
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index 22482870..81b72c6e 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -20,12 +20,14 @@ class FilterSettingsMixin(models.Model):
dm_content = models.CharField(
max_length=1000,
null=True,
+ blank=True,
help_text="The DM to send to a user triggering this filter."
)
dm_embed = models.CharField(
max_length=2000,
help_text="The content of the DM embed",
- null=True
+ null=True,
+ blank=True
)
infraction_type = models.CharField(
choices=[(choices[0].upper(), choices[1]) for choices in Infraction.TYPE_CHOICES],
@@ -36,6 +38,7 @@ class FilterSettingsMixin(models.Model):
infraction_reason = models.CharField(
max_length=1000,
help_text="The reason to give for the infraction.",
+ blank=True,
null=True
)
infraction_duration = models.DurationField(
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index 7a5e76b7..a42d567b 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -151,6 +151,13 @@ ALWAYS_OPTIONAL_SETTINGS = (
'infraction_channel',
)
+ALWAYS_BLANKABLE_SETTINGS = (
+ 'dm_content',
+ 'dm_embed',
+ 'infraction_type',
+ 'infraction_reason',
+)
+
REQUIRED_FOR_FILTER_LIST_SETTINGS = (
'guild_pings',
'filter_dm',
@@ -310,7 +317,10 @@ class FilterListSerializer(ModelSerializer):
extra_kwargs = {
field: {'required': False, 'allow_null': True} for field in ALWAYS_OPTIONAL_SETTINGS
} | {
- 'infraction_reason': {'allow_blank': True, 'allow_null': True, 'required': False},
+ field: {'allow_blank': True, 'allow_null': True, 'required': False}
+ for field in ALWAYS_BLANKABLE_SETTINGS
+ } | {
+ 'bypass_roles': {'allow_empty': True},
'enabled_channels': {'allow_empty': True},
'disabled_channels': {'allow_empty': True},
'enabled_categories': {'allow_empty': True},