aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/api')
-rw-r--r--pydis_site/apps/api/migrations/0074_merge_20211017_0822.py14
-rw-r--r--pydis_site/apps/api/migrations/0075_prepare_filter_and_filterlist_for_new_filter_schema.py95
-rw-r--r--pydis_site/apps/api/migrations/0078_merge_20211218_2200.py14
-rw-r--r--pydis_site/apps/api/migrations/0079_dm_embed_and_alert_fields.py58
-rw-r--r--pydis_site/apps/api/migrations/0079_new_filter_schema.py (renamed from pydis_site/apps/api/migrations/0070_new_filter_schema.py)61
5 files changed, 36 insertions, 206 deletions
diff --git a/pydis_site/apps/api/migrations/0074_merge_20211017_0822.py b/pydis_site/apps/api/migrations/0074_merge_20211017_0822.py
deleted file mode 100644
index ae41ac71..00000000
--- a/pydis_site/apps/api/migrations/0074_merge_20211017_0822.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Generated by Django 3.0.14 on 2021-10-17 08:22
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('api', '0073_otn_allow_GT_and_LT'),
- ('api', '0070_new_filter_schema'),
- ]
-
- operations = [
- ]
diff --git a/pydis_site/apps/api/migrations/0075_prepare_filter_and_filterlist_for_new_filter_schema.py b/pydis_site/apps/api/migrations/0075_prepare_filter_and_filterlist_for_new_filter_schema.py
deleted file mode 100644
index 1e24b379..00000000
--- a/pydis_site/apps/api/migrations/0075_prepare_filter_and_filterlist_for_new_filter_schema.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# Generated by Django 3.0.14 on 2021-12-11 23:14
-from django.apps.registry import Apps
-from django.db import migrations, models
-from django.db.backends.base.schema import BaseDatabaseSchemaEditor
-
-
-def migrate_filterlist(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
- FilterList = apps.get_model("api", "FilterList")
- change_map = {
- "filter_token": "token",
- "domain_name": "domain",
- "guild_invite": "invite",
- "file_format": "extension"
- }
- for filter_list in FilterList.objects.all():
- if change_map.get(filter_list.name):
- filter_list.name = change_map.get(filter_list.name)
- filter_list.save()
- redirects = FilterList(
- name="redirect",
- ping_type=[],
- dm_ping_type=[],
- enabled_channels=[],
- disabled_channels=[],
- disabled_categories=[],
- list_type=0,
- filter_dm=True,
- delete_messages=False,
- bypass_roles=["staff"],
- enabled=True
- )
- redirects.save()
-
-
-def unmigrate_filterlist(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
- FilterList = apps.get_model("api", "FilterList")
- change_map = {
- "token": "filter_token",
- "domain": "domain_name",
- "invite": "guild_invite",
- "format": "file_format"
- }
- for filter_list in FilterList.objects.all():
- if change_map.get(filter_list.name):
- filter_list.name = change_map.get(filter_list.name)
- filter_list.save()
- FilterList.objects.filter(name="redirect").delete()
-
-
-class Migration(migrations.Migration):
- dependencies = [
- ('api', '0074_merge_20211017_0822'),
- ]
-
- operations = [
- migrations.RenameField(
- model_name='filter',
- old_name='allowed_categories',
- new_name='disabled_categories',
- ),
- migrations.RenameField(
- model_name='filter',
- old_name='allowed_channels',
- new_name='disabled_channels',
- ),
- migrations.RenameField(
- model_name='filter',
- old_name='disallowed_channels',
- new_name='enabled_channels',
- ),
- migrations.RenameField(
- model_name='filterlist',
- old_name='allowed_categories',
- new_name='disabled_categories',
- ),
- migrations.RenameField(
- model_name='filterlist',
- old_name='allowed_channels',
- new_name='disabled_channels',
- ),
- migrations.RenameField(
- model_name='filterlist',
- old_name='disallowed_channels',
- new_name='enabled_channels',
- ),
- migrations.RemoveField(
- model_name='filterlist',
- name='disallowed_categories',
- ),
- migrations.RemoveField(
- model_name='filter',
- name='disallowed_categories',
- ),
- migrations.RunPython(migrate_filterlist, unmigrate_filterlist)
- ]
diff --git a/pydis_site/apps/api/migrations/0078_merge_20211218_2200.py b/pydis_site/apps/api/migrations/0078_merge_20211218_2200.py
deleted file mode 100644
index 7fe559f5..00000000
--- a/pydis_site/apps/api/migrations/0078_merge_20211218_2200.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Generated by Django 3.1.14 on 2021-12-18 22:00
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('api', '0075_prepare_filter_and_filterlist_for_new_filter_schema'),
- ('api', '0077_use_generic_jsonfield'),
- ]
-
- operations = [
- ]
diff --git a/pydis_site/apps/api/migrations/0079_dm_embed_and_alert_fields.py b/pydis_site/apps/api/migrations/0079_dm_embed_and_alert_fields.py
deleted file mode 100644
index cae175df..00000000
--- a/pydis_site/apps/api/migrations/0079_dm_embed_and_alert_fields.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Generated by Django 3.1.14 on 2021-12-19 23:05
-from django.apps.registry import Apps
-from django.db import migrations, models
-from django.db.backends.base.schema import BaseDatabaseSchemaEditor
-
-
-def migrate_filterlist(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
- FilterList = apps.get_model("api", "FilterList")
- change_map = {
- "token": True,
- "domain": True,
- "invite": True,
- "extension": False,
- "redirect": False
- }
- for filter_list in FilterList.objects.all():
- filter_list.send_alert = change_map.get(filter_list.name)
- filter_list.dm_embed = ""
- filter_list.save()
-
-
-def unmigrate_filterlist(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
- FilterList = apps.get_model("api", "FilterList")
- for filter_list in FilterList.objects.all():
- filter_list.send_alert = True
- filter_list.server_message_embed = None
- filter_list.save()
-
-
-class Migration(migrations.Migration):
- dependencies = [
- ('api', '0078_merge_20211213_0552'),
- ('api', '0078_merge_20211218_2200'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='filter',
- name='send_alert',
- field=models.BooleanField(help_text='Whether alert should be sent.', null=True),
- ),
- migrations.AddField(
- model_name='filter',
- name='dm_embed',
- field=models.CharField(help_text='The content of the DM embed', max_length=2000, null=True),
- ),
- migrations.AddField(
- model_name='filterlist',
- name='send_alert',
- field=models.BooleanField(default=True, help_text='Whether alert should be sent.'),
- ),
- migrations.AddField(
- model_name='filterlist',
- name='dm_embed',
- field=models.CharField(help_text='The content of the DM embed', max_length=2000, null=True),
- ),
- migrations.RunPython(migrate_filterlist, unmigrate_filterlist)
- ]
diff --git a/pydis_site/apps/api/migrations/0070_new_filter_schema.py b/pydis_site/apps/api/migrations/0079_new_filter_schema.py
index f33c112b..94494186 100644
--- a/pydis_site/apps/api/migrations/0070_new_filter_schema.py
+++ b/pydis_site/apps/api/migrations/0079_new_filter_schema.py
@@ -9,7 +9,14 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditor
import pydis_site.apps.api.models.bot.filters
-OLD_LIST_NAMES = (('GUILD_INVITE', 'ALLOW'), ('FILE_FORMAT', 'DENY'), ('DOMAIN_NAME', 'DENY'), ('FILTER_TOKEN', 'DENY'))
+OLD_LIST_NAMES = (('GUILD_INVITE', 'ALLOW'), ('FILE_FORMAT', 'DENY'), ('DOMAIN_NAME', 'DENY'), ('FILTER_TOKEN', 'DENY'), ('REDIRECT', 'DENY'))
+change_map = {
+ "FILTER_TOKEN": "token",
+ "DOMAIN_NAME": "domain",
+ "GUILD_INVITE": "invite",
+ "FILE_FORMAT": "extension",
+ "REDIRECT": "redirect"
+}
def forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
@@ -28,22 +35,23 @@ def forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
dm_content = ""
list_ = filter_list.objects.create(
- name=name.lower(),
+ name=change_map[name],
list_type=1 if type_ == "ALLOW" else 0,
- ping_type=(["onduty"] if name != "FILE_FORMAT" else []),
+ ping_type=(["Moderators"] if name != "FILE_FORMAT" else []),
filter_dm=True,
dm_ping_type=[],
delete_messages=(True if name != "FILTER_TOKEN" else False),
- bypass_roles=["staff"],
+ bypass_roles=["Helpers"],
enabled=True,
dm_content=dm_content,
+ dm_embed="",
infraction_type="",
infraction_reason="",
infraction_duration=timedelta(seconds=0),
- disallowed_channels=[],
- disallowed_categories=[],
- allowed_channels=[],
- allowed_categories=[]
+ disabled_channels=[],
+ disabled_categories=(["CODE JAM"] if name in ("FILE_FORMAT", "GUILD_INVITE") else []),
+ enabled_channels=[],
+ send_alert=(name in ('GUILD_INVITE', 'DOMAIN_NAME', 'FILTER_TOKEN'))
)
for object_ in objects:
@@ -59,13 +67,14 @@ def forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
bypass_roles=None,
enabled=None,
dm_content=None,
+ dm_embed=None,
infraction_type=None,
infraction_reason=None,
infraction_duration=None,
- disallowed_channels=None,
- disallowed_categories=None,
- allowed_channels=None,
- allowed_categories=None
+ disabled_channels=None,
+ disabled_categories=None,
+ enabled_channels=None,
+ send_alert=None,
)
new_object.save()
@@ -73,7 +82,7 @@ def forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
class Migration(migrations.Migration):
dependencies = [
- ('api', '0069_documentationlink_validators'),
+ ('api', '0078_merge_20211213_0552'),
]
operations = [
@@ -88,20 +97,21 @@ class Migration(migrations.Migration):
('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, 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)),
+ ('ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), 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)),
+ ('dm_ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), 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)),
('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, validators=[pydis_site.apps.api.models.bot.filters.validate_bypass_roles_field], 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)),
('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, null=True)),
('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)),
- ('disallowed_categories', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None)),
- ('allowed_channels', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None)),
- ('allowed_categories', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None)),
+ ('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)),
+ ('disabled_categories', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Categories in which to not run the filter.", null=True, size=None)),
+ ('enabled_channels', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Channels in which to run the filter even if it's disabled in the category.", null=True, size=None)),
+ ('send_alert', models.BooleanField(help_text='Whether an alert should be sent.', null=True)),
],
),
migrations.CreateModel(
@@ -110,20 +120,21 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='The unique name of this list.', max_length=50)),
('list_type', models.IntegerField(choices=[(1, 'Allow'), (0, 'Deny')], help_text='Whether this list is an allowlist or denylist')),
- ('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])),
+ ('ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text='Who to ping when this filter triggers.', size=None, validators=[pydis_site.apps.api.models.bot.filters.validate_ping_field])),
('filter_dm', models.BooleanField(help_text='Whether DMs should be filtered.')),
- ('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])),
+ ('dm_ping_type', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), 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])),
('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, validators=[pydis_site.apps.api.models.bot.filters.validate_bypass_roles_field])),
('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)),
('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)),
- ('disallowed_categories', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), size=None)),
- ('allowed_channels', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), size=None)),
- ('allowed_categories', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), size=None)),
+ ('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)),
+ ('disabled_categories', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Categories in which to not run the filter.", size=None)),
+ ('enabled_channels', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text="Channels in which to run the filter even if it's disabled in the category.", size=None)),
+ ('send_alert', models.BooleanField(help_text='Whether an alert should be sent.')),
],
),
migrations.AddField(