aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps')
-rw-r--r--pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py (renamed from pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py)21
-rw-r--r--pydis_site/apps/api/models/__init__.py2
-rw-r--r--pydis_site/apps/api/models/bot/__init__.py2
-rw-r--r--pydis_site/apps/api/models/bot/allow_deny_list.py (renamed from pydis_site/apps/api/models/bot/allowlist.py)18
-rw-r--r--pydis_site/apps/api/serializers.py8
-rw-r--r--pydis_site/apps/api/tests/test_allowlists.py14
-rw-r--r--pydis_site/apps/api/urls.py6
-rw-r--r--pydis_site/apps/api/viewsets/__init__.py2
-rw-r--r--pydis_site/apps/api/viewsets/bot/__init__.py2
-rw-r--r--pydis_site/apps/api/viewsets/bot/allow_deny_list.py (renamed from pydis_site/apps/api/viewsets/bot/allowlist.py)28
10 files changed, 48 insertions, 55 deletions
diff --git a/pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py b/pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py
index 45650d86..c450344b 100644
--- a/pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py
+++ b/pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py
@@ -5,33 +5,28 @@ import pydis_site.apps.api.models.mixins
class Migration(migrations.Migration):
-
dependencies = [
('api', '0056_allow_blank_user_roles'),
]
operations = [
migrations.CreateModel(
- name='AllowList',
+ name='AllowDenyList',
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)),
- ('type', models.CharField(choices=[('GUILD_INVITE_ID', 'Guild Invite Id'), ('FILE_FORMAT', 'File Format'), ('DOMAIN_NAME', 'Domain Name'), ('WORD_WATCHLIST', 'Word Watchlist')], help_text='The type of allowlist this is on.', max_length=50)),
+ ('type', models.CharField(
+ choices=[('GUILD_INVITE_ID', 'Guild Invite Id'), ('FILE_FORMAT', 'File Format'),
+ ('DOMAIN_NAME', 'Domain Name'), ('WORD_WATCHLIST', 'Word Watchlist')],
+ help_text='The type of allowlist this is on.', max_length=50)),
('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.')),
+ ('content', models.TextField(help_text='The data to add to the allow or denylist.')),
],
- options={
- 'abstract': False,
- },
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
),
- migrations.AlterModelTable(
- name='allowlist',
- table='allow_list',
- ),
migrations.AddConstraint(
- model_name='allowlist',
- constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_allowlist'),
+ model_name='allowdenylist',
+ constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_allow_deny_list'),
)
]
diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py
index 2839fbba..34973a8d 100644
--- a/pydis_site/apps/api/models/__init__.py
+++ b/pydis_site/apps/api/models/__init__.py
@@ -1,6 +1,6 @@
# flake8: noqa
from .bot import (
- AllowList,
+ AllowDenyList,
BotSetting,
DocumentationLink,
DeletedMessage,
diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py
index b373ee84..1234b35a 100644
--- a/pydis_site/apps/api/models/bot/__init__.py
+++ b/pydis_site/apps/api/models/bot/__init__.py
@@ -1,5 +1,5 @@
# flake8: noqa
-from .allowlist import AllowList
+from .allow_deny_list import AllowDenyList
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/allow_deny_list.py
index fc57ef32..1eef47ba 100644
--- a/pydis_site/apps/api/models/bot/allowlist.py
+++ b/pydis_site/apps/api/models/bot/allow_deny_list.py
@@ -3,11 +3,11 @@ from django.db import models
from pydis_site.apps.api.models.mixins import ModelReprMixin, ModelTimestampMixin
-class AllowList(ModelTimestampMixin, ModelReprMixin, models.Model):
+class AllowDenyList(ModelTimestampMixin, ModelReprMixin, models.Model):
"""An item that is either allowed or denied."""
- AllowListType = models.TextChoices(
- 'AllowListType',
+ AllowDenyListType = models.TextChoices(
+ 'AllowDenyListType',
'GUILD_INVITE_ID '
'FILE_FORMAT '
'DOMAIN_NAME '
@@ -16,24 +16,22 @@ class AllowList(ModelTimestampMixin, ModelReprMixin, models.Model):
type = models.CharField(
max_length=50,
help_text="The type of allowlist this is on.",
- choices=AllowListType.choices,
+ choices=AllowDenyListType.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."
+ help_text="The data to add to the allow or denylist."
)
class Meta:
"""Metaconfig for this model."""
- db_table = 'allow_list'
-
- # This constraint ensures only one allowlist with the same content
- # can exist per type.This means that we cannot have both an allow
+ # This constraint ensures only one allow or denylist with the
+ # same content can exist. This means that we cannot have both an allow
# and a deny for the same item, and we cannot have duplicates of the
# same item.
constraints = [
- models.UniqueConstraint(fields=['content', 'type'], name='unique_allowlist'),
+ models.UniqueConstraint(fields=['content', 'type'], name='unique_allow_deny_list'),
]
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index 13030074..d532dd69 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -4,7 +4,7 @@ from rest_framework.validators import UniqueTogetherValidator
from rest_framework_bulk import BulkSerializerMixin
from .models import (
- AllowList,
+ AllowDenyList,
BotSetting,
DeletedMessage,
DocumentationLink,
@@ -104,13 +104,13 @@ class DocumentationLinkSerializer(ModelSerializer):
fields = ('package', 'base_url', 'inventory_url')
-class AllowListSerializer(ModelSerializer):
- """A class providing (de-)serialization of `AllowList` instances."""
+class AllowDenyListSerializer(ModelSerializer):
+ """A class providing (de-)serialization of `AllowDenyList` instances."""
class Meta:
"""Metadata defined for the Django REST Framework."""
- model = AllowList
+ model = AllowDenyList
fields = ('id', 'created_at', 'updated_at', 'type', 'allowed', 'content')
diff --git a/pydis_site/apps/api/tests/test_allowlists.py b/pydis_site/apps/api/tests/test_allowlists.py
index c6004439..5aa50670 100644
--- a/pydis_site/apps/api/tests/test_allowlists.py
+++ b/pydis_site/apps/api/tests/test_allowlists.py
@@ -1,9 +1,9 @@
from django_hosts.resolvers import reverse
-from .base import APISubdomainTestCase
-from ..models import AllowList
+from pydis_site.apps.api.models import AllowDenyList
+from pydis_site.apps.api.tests.base import APISubdomainTestCase
-URL = reverse('bot:allowlist-list', host='api')
+URL = reverse('bot:allowdenylist-list', host='api')
JPEG_ALLOWLIST = {
"type": 'FILE_FORMAT',
"allowed": True,
@@ -38,8 +38,8 @@ class EmptyDatabaseTests(APISubdomainTestCase):
class FetchTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls):
- cls.jpeg_format = AllowList.objects.create(**JPEG_ALLOWLIST)
- cls.png_format = AllowList.objects.create(**PNG_ALLOWLIST)
+ cls.jpeg_format = AllowDenyList.objects.create(**JPEG_ALLOWLIST)
+ cls.png_format = AllowDenyList.objects.create(**PNG_ALLOWLIST)
def test_returns_name_in_list(self):
response = self.client.get(URL)
@@ -83,8 +83,8 @@ class CreationTests(APISubdomainTestCase):
class DeletionTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls):
- cls.jpeg_format = AllowList.objects.create(**JPEG_ALLOWLIST)
- cls.png_format = AllowList.objects.create(**PNG_ALLOWLIST)
+ cls.jpeg_format = AllowDenyList.objects.create(**JPEG_ALLOWLIST)
+ cls.png_format = AllowDenyList.objects.create(**PNG_ALLOWLIST)
def test_deleting_unknown_id_returns_404(self):
response = self.client.delete(f"{URL}/200")
diff --git a/pydis_site/apps/api/urls.py b/pydis_site/apps/api/urls.py
index bf41f09f..b6ed2914 100644
--- a/pydis_site/apps/api/urls.py
+++ b/pydis_site/apps/api/urls.py
@@ -3,7 +3,7 @@ from rest_framework.routers import DefaultRouter
from .views import HealthcheckView, RulesView
from .viewsets import (
- AllowListViewSet,
+ AllowDenyListViewSet,
BotSettingViewSet,
DeletedMessageViewSet,
DocumentationLinkViewSet,
@@ -22,8 +22,8 @@ from .viewsets import (
# http://www.django-rest-framework.org/api-guide/routers/#defaultrouter
bot_router = DefaultRouter(trailing_slash=False)
bot_router.register(
- 'allowlists',
- AllowListViewSet
+ 'allow_deny_lists',
+ AllowDenyListViewSet
)
bot_router.register(
'bot-settings',
diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py
index 98d3d586..eb7d5098 100644
--- a/pydis_site/apps/api/viewsets/__init__.py
+++ b/pydis_site/apps/api/viewsets/__init__.py
@@ -1,6 +1,6 @@
# flake8: noqa
from .bot import (
- AllowListViewSet,
+ AllowDenyListViewSet,
BotSettingViewSet,
DeletedMessageViewSet,
DocumentationLinkViewSet,
diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py
index 86bfc910..11638dd8 100644
--- a/pydis_site/apps/api/viewsets/bot/__init__.py
+++ b/pydis_site/apps/api/viewsets/bot/__init__.py
@@ -1,5 +1,5 @@
# flake8: noqa
-from .allowlist import AllowListViewSet
+from .allow_deny_list import AllowDenyListViewSet
from .bot_setting import BotSettingViewSet
from .deleted_message import DeletedMessageViewSet
from .documentation_link import DocumentationLinkViewSet
diff --git a/pydis_site/apps/api/viewsets/bot/allowlist.py b/pydis_site/apps/api/viewsets/bot/allow_deny_list.py
index 7cc82ff7..a2499d89 100644
--- a/pydis_site/apps/api/viewsets/bot/allowlist.py
+++ b/pydis_site/apps/api/viewsets/bot/allow_deny_list.py
@@ -1,16 +1,16 @@
from rest_framework.viewsets import ModelViewSet
-from pydis_site.apps.api.models.bot.allowlist import AllowList
-from pydis_site.apps.api.serializers import AllowListSerializer
+from pydis_site.apps.api.models.bot.allow_deny_list import AllowDenyList
+from pydis_site.apps.api.serializers import AllowDenyListSerializer
-class AllowListViewSet(ModelViewSet):
+class AllowDenyListViewSet(ModelViewSet):
"""
- View providing CRUD operations on items whitelisted or blacklisted by our bot.
+ View providing CRUD operations on items allowed or denied by our bot.
## Routes
- ### GET /bot/allowlists
- Returns all allowlist items in the database.
+ ### GET /bot/allow_deny_lists
+ Returns all allow and denylist items in the database.
#### Response format
>>> [
@@ -29,8 +29,8 @@ class AllowListViewSet(ModelViewSet):
- 200: returned on success
- 401: returned if unauthenticated
- ### GET /bot/allowlists/<id:int>
- Returns a specific AllowList item from the database.
+ ### GET /bot/allow_deny_lists/<id:int>
+ Returns a specific AllowDenyList item from the database.
#### Response format
>>> {
@@ -46,8 +46,8 @@ class AllowListViewSet(ModelViewSet):
- 200: returned on success
- 404: returned if the id was not found.
- ### POST /bot/allowedlists
- Adds a single allowedlist item to the database.
+ ### POST /bot/allow_deny_lists
+ Adds a single AllowDenyList item to the database.
#### Request body
>>> {
@@ -60,13 +60,13 @@ class AllowListViewSet(ModelViewSet):
- 201: returned on success
- 400: if one of the given fields is invalid
- ### DELETE /bot/allowedlists/<id:int>
- Deletes the tag with the given `id`.
+ ### DELETE /bot/allow_deny_lists/<id:int>
+ Deletes the AllowDenyList item with the given `id`.
#### Status codes
- 204: returned on success
- 404: if a tag with the given `id` does not exist
"""
- serializer_class = AllowListSerializer
- queryset = AllowList.objects.all()
+ serializer_class = AllowDenyListSerializer
+ queryset = AllowDenyList.objects.all()