diff options
| author | 2022-11-05 15:20:14 +0200 | |
|---|---|---|
| committer | 2022-11-05 15:20:14 +0200 | |
| commit | 649fbc4799082f6ad5d9f986c86ca37ae6fe859d (patch) | |
| tree | 52e31beaef2bc1654fcf898b6a35e89daaa9627e /pydis_site/apps | |
| parent | Stop using None as a valid setting value (diff) | |
Add creation and update timestamps to filtering models
This is to support auto-infractions reporting (bot 7fcec400)
Diffstat (limited to 'pydis_site/apps')
| -rw-r--r-- | pydis_site/apps/api/migrations/0085_new_filter_schema.py | 6 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/bot/filters.py | 7 | ||||
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 8 | 
3 files changed, 14 insertions, 7 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 b0665ba5..d902be7f 100644 --- a/pydis_site/apps/api/migrations/0085_new_filter_schema.py +++ b/pydis_site/apps/api/migrations/0085_new_filter_schema.py @@ -60,6 +60,8 @@ def forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:          for object_ in objects:              new_object = filter_.objects.create(                  content=object_.content, +                created_at=object_.created_at, +                updated_at=object_.updated_at,                  filter_list=list_,                  description=object_.comment,                  additional_field=None, @@ -99,6 +101,8 @@ class Migration(migrations.Migration):              name='Filter',              fields=[                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), +                ('created_at', models.DateTimeField(auto_now_add=True)), +                ('updated_at', models.DateTimeField(auto_now=True)),                  ('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', models.JSONField(help_text='Implementation specific field.', null=True)), @@ -125,6 +129,8 @@ class Migration(migrations.Migration):              name='FilterList',              fields=[                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), +                ('created_at', models.DateTimeField(auto_now_add=True)), +                ('updated_at', models.DateTimeField(auto_now=True)),                  ('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')),                  ('guild_pings', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), help_text='Who to ping when this filter triggers.', size=None)), diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py index 7398f8a0..1ea21a48 100644 --- a/pydis_site/apps/api/models/bot/filters.py +++ b/pydis_site/apps/api/models/bot/filters.py @@ -5,6 +5,7 @@ from django.db.models import UniqueConstraint  # Must be imported that way to avoid circular imports  from .infraction import Infraction +from pydis_site.apps.api.models.mixins import ModelTimestampMixin, ModelReprMixin  class FilterListType(models.IntegerChoices): @@ -14,7 +15,7 @@ class FilterListType(models.IntegerChoices):      DENY = 0 -class FilterList(models.Model): +class FilterList(ModelTimestampMixin, ModelReprMixin, models.Model):      """Represent a list in its allow or deny form."""      name = models.CharField(max_length=50, help_text="The unique name of this list.") @@ -119,7 +120,7 @@ class FilterList(models.Model):          return f"Filter {FilterListType(self.list_type).label}list {self.name!r}" -class FilterBase(models.Model): +class FilterBase(ModelTimestampMixin, ModelReprMixin, models.Model):      """One specific trigger of a list."""      content = models.CharField(max_length=100, help_text="The definition of this filter.") @@ -247,7 +248,7 @@ class Filter(FilterBase):              UniqueConstraint(                  fields=tuple(                      [field.name for field in FilterBase._meta.fields -                     if field.name != "id" and field.name != "description"] +                     if field.name not in ("id", "description", "created_at", "updated_at")]                  ),                  name="unique_filters"),          ) diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index a902523e..d6bae2cb 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -181,8 +181,8 @@ ALLOW_EMPTY_SETTINGS = (  )  # Required fields for custom JSON representation purposes -BASE_FILTER_FIELDS = ('id', 'content', 'description', 'additional_field') -BASE_FILTERLIST_FIELDS = ('id', 'name', 'list_type') +BASE_FILTER_FIELDS = ('id', 'created_at', 'updated_at', 'content', 'description', 'additional_field') +BASE_FILTERLIST_FIELDS = ('id', 'created_at', 'updated_at', 'name', 'list_type')  BASE_SETTINGS_FIELDS = (      "bypass_roles",      "filter_dm", @@ -253,7 +253,7 @@ class FilterSerializer(ModelSerializer):          model = Filter          fields = ( -            'id', 'content', 'description', 'additional_field', 'filter_list' +            'id', 'created_at', 'updated_at', 'content', 'description', 'additional_field', 'filter_list'          ) + SETTINGS_FIELDS          extra_kwargs = _create_filter_meta_extra_kwargs() @@ -331,7 +331,7 @@ class FilterListSerializer(ModelSerializer):          """Metadata defined for the Django REST Framework."""          model = FilterList -        fields = ('id', 'name', 'list_type', 'filters') + SETTINGS_FIELDS +        fields = ('id', 'created_at', 'updated_at', 'name', 'list_type', 'filters') + SETTINGS_FIELDS          extra_kwargs = _create_filter_list_meta_extra_kwargs()          # Ensure there can only be one filter list with the same name and type. | 
