aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-07-14 15:48:34 +0200
committerGravatar Leon Sandøy <[email protected]>2020-07-14 15:48:34 +0200
commitee743f622dd0ba6f8c0b9801b1db1d85d60fa697 (patch)
tree09e66d2d24f26b46f86349a0816ef3440e6ff360
parentAdd a mixin for adding created and updated times. (diff)
Add the AllowList model and serializer.
This is the model which we will use for items that are either blacklisted or whitelisted. https://github.com/python-discord/site/issues/305
-rw-r--r--pydis_site/apps/api/models/__init__.py1
-rw-r--r--pydis_site/apps/api/models/bot/__init__.py1
-rw-r--r--pydis_site/apps/api/models/bot/allowlist.py28
-rw-r--r--pydis_site/apps/api/serializers.py12
4 files changed, 41 insertions, 1 deletions
diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py
index 1c9e1d07..04d0fc50 100644
--- a/pydis_site/apps/api/models/__init__.py
+++ b/pydis_site/apps/api/models/__init__.py
@@ -1,5 +1,6 @@
# flake8: noqa
from .bot import (
+ AllowList,
BotSetting,
DocumentationLink,
DeletedMessage,
diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py
index 8ae47746..b373ee84 100644
--- a/pydis_site/apps/api/models/bot/__init__.py
+++ b/pydis_site/apps/api/models/bot/__init__.py
@@ -1,4 +1,5 @@
# flake8: noqa
+from .allowlist import AllowList
from .bot_setting import BotSetting
from .deleted_message import DeletedMessage
from .documentation_link import DocumentationLink
diff --git a/pydis_site/apps/api/models/bot/allowlist.py b/pydis_site/apps/api/models/bot/allowlist.py
new file mode 100644
index 00000000..c8fa2e33
--- /dev/null
+++ b/pydis_site/apps/api/models/bot/allowlist.py
@@ -0,0 +1,28 @@
+from django.db import models
+
+from pydis_site.apps.api.models import ModelReprMixin, ModelTimestampMixin
+
+
+class AllowList(ModelTimestampMixin, ModelReprMixin, models.Model):
+ """An item that is either allowed or denied."""
+
+ AllowListType = models.TextChoices(
+ 'guild_invite_id',
+ 'file_format',
+ 'domain_name',
+ 'word_watchlist',
+ )
+ type = models.CharField(
+ max_length=50,
+ help_text=(
+ "The type of allowlist this is on. The value must be one of the following: "
+ f"{','.join(AllowListType.choices)}."
+ ),
+ choices=AllowListType.choices,
+ )
+ allowed = models.BooleanField(
+ help_text="Whether this item is on the allowlist or the denylist."
+ )
+ content = models.TextField(
+ help_text="The data to add to the allowlist."
+ )
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index f2d5144c..24ba0ec0 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -8,7 +8,7 @@ from .models import (
DocumentationLink, Infraction,
LogEntry, MessageDeletionContext,
Nomination, OffTopicChannelName,
- OffensiveMessage,
+ OffensiveMessage, AllowList,
Reminder, Role,
Tag, User
)
@@ -97,6 +97,16 @@ class DocumentationLinkSerializer(ModelSerializer):
fields = ('package', 'base_url', 'inventory_url')
+class AllowListSerializer(ModelSerializer):
+ """A class providing (de-)serialization of `AllowList` instances."""
+
+ class Meta:
+ """Metadata defined for the Django REST Framework."""
+
+ model = AllowList
+ fields = ('created_at', 'updated_at', 'type', 'allowed', 'content')
+
+
class InfractionSerializer(ModelSerializer):
"""A class providing (de-)serialization of `Infraction` instances."""