diff options
| author | 2020-07-27 09:53:38 +0200 | |
|---|---|---|
| committer | 2020-07-27 09:53:38 +0200 | |
| commit | 285c81bc13e996246ad9463951853fc12903d766 (patch) | |
| tree | ce6d40f8bdf494cb438f94676e16fbf98c167a37 | |
| parent | Minor changes to tests, use subTest. (diff) | |
Rename AllowDenyList to FilterList
| -rw-r--r-- | pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py (renamed from pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py) | 6 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/bot/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/bot/filter_list.py (renamed from pydis_site/apps/api/models/bot/allow_deny_list.py) | 12 | ||||
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 10 | ||||
| -rw-r--r-- | pydis_site/apps/api/tests/test_filterlists.py (renamed from pydis_site/apps/api/tests/test_allowlists.py) | 18 | ||||
| -rw-r--r-- | pydis_site/apps/api/urls.py | 7 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/filter_list.py (renamed from pydis_site/apps/api/viewsets/bot/allow_deny_list.py) | 34 | 
10 files changed, 47 insertions, 48 deletions
| diff --git a/pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py b/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py index ab8c5f3f..44025ee8 100644 --- a/pydis_site/apps/api/migrations/0057_create_new_allowdenylist_model.py +++ b/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py @@ -11,7 +11,7 @@ class Migration(migrations.Migration):      operations = [          migrations.CreateModel( -            name='AllowDenyList', +            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)), @@ -27,7 +27,7 @@ class Migration(migrations.Migration):              bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),          ),          migrations.AddConstraint( -            model_name='allowdenylist', -            constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_allow_deny_list'), +            model_name='filterlist', +            constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_filter_list'),          )      ] diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py index 34973a8d..1d0ab7ea 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 ( -    AllowDenyList, +    FilterList,      BotSetting,      DocumentationLink,      DeletedMessage, diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py index 1234b35a..efd98184 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 .allow_deny_list import AllowDenyList +from .filter_list import FilterList  from .bot_setting import BotSetting  from .deleted_message import DeletedMessage  from .documentation_link import DocumentationLink diff --git a/pydis_site/apps/api/models/bot/allow_deny_list.py b/pydis_site/apps/api/models/bot/filter_list.py index e1e09a78..d279e137 100644 --- a/pydis_site/apps/api/models/bot/allow_deny_list.py +++ b/pydis_site/apps/api/models/bot/filter_list.py @@ -3,11 +3,11 @@ from django.db import models  from pydis_site.apps.api.models.mixins import ModelReprMixin, ModelTimestampMixin -class AllowDenyList(ModelTimestampMixin, ModelReprMixin, models.Model): +class FilterList(ModelTimestampMixin, ModelReprMixin, models.Model):      """An item that is either allowed or denied.""" -    AllowDenyListType = models.TextChoices( -        'AllowDenyListType', +    FilterListType = models.TextChoices( +        'FilterListType',          'GUILD_INVITE '          'FILE_FORMAT '          'DOMAIN_NAME ' @@ -16,7 +16,7 @@ class AllowDenyList(ModelTimestampMixin, ModelReprMixin, models.Model):      type = models.CharField(          max_length=50,          help_text="The type of allowlist this is on.", -        choices=AllowDenyListType.choices, +        choices=FilterListType.choices,      )      allowed = models.BooleanField(          help_text="Whether this item is on the allowlist or the denylist." @@ -32,10 +32,10 @@ class AllowDenyList(ModelTimestampMixin, ModelReprMixin, models.Model):      class Meta:          """Metaconfig for this model.""" -        # This constraint ensures only one allow or denylist with the +        # This constraint ensures only one filterlist 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_allow_deny_list'), +            models.UniqueConstraint(fields=['content', 'type'], name='unique_filter_list'),          ] diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 50f27f1d..8fd40da7 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -4,10 +4,10 @@ from rest_framework.validators import UniqueTogetherValidator  from rest_framework_bulk import BulkSerializerMixin  from .models import ( -    AllowDenyList,      BotSetting,      DeletedMessage,      DocumentationLink, +    FilterList,      Infraction,      LogEntry,      MessageDeletionContext, @@ -17,7 +17,7 @@ from .models import (      Reminder,      Role,      Tag, -    User, +    User  ) @@ -104,13 +104,13 @@ class DocumentationLinkSerializer(ModelSerializer):          fields = ('package', 'base_url', 'inventory_url') -class AllowDenyListSerializer(ModelSerializer): -    """A class providing (de-)serialization of `AllowDenyList` instances.""" +class FilterListSerializer(ModelSerializer): +    """A class providing (de-)serialization of `FilterList` instances."""      class Meta:          """Metadata defined for the Django REST Framework.""" -        model = AllowDenyList +        model = FilterList          fields = ('id', 'created_at', 'updated_at', 'type', 'allowed', 'content', 'comment') diff --git a/pydis_site/apps/api/tests/test_allowlists.py b/pydis_site/apps/api/tests/test_filterlists.py index fd8772d0..b577c31c 100644 --- a/pydis_site/apps/api/tests/test_allowlists.py +++ b/pydis_site/apps/api/tests/test_filterlists.py @@ -1,9 +1,9 @@  from django_hosts.resolvers import reverse -from pydis_site.apps.api.models import AllowDenyList +from pydis_site.apps.api.models import FilterList  from pydis_site.apps.api.tests.base import APISubdomainTestCase -URL = reverse('bot:allowdenylist-list', host='api') +URL = reverse('bot:filterlist-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 = AllowDenyList.objects.create(**JPEG_ALLOWLIST) -        cls.png_format = AllowDenyList.objects.create(**PNG_ALLOWLIST) +        cls.jpeg_format = FilterList.objects.create(**JPEG_ALLOWLIST) +        cls.png_format = FilterList.objects.create(**PNG_ALLOWLIST)      def test_returns_name_in_list(self):          response = self.client.get(URL) @@ -54,11 +54,11 @@ class FetchTests(APISubdomainTestCase):          self.assertEqual(response.status_code, 200)          self.assertEqual(response.json().get("content"), self.jpeg_format.content) -    def test_returns_allow_deny_list_types(self): -        response = self.client.get(f'{URL}/get_types') +    def test_returns_filter_list_types(self): +        response = self.client.get(f'{URL}/get-types')          self.assertEqual(response.status_code, 200) -        for api_type, model_type in zip(response.json(), AllowDenyList.AllowDenyListType.choices): +        for api_type, model_type in zip(response.json(), FilterList.FilterListType.choices):              self.assertEquals(api_type[0], model_type[0])              self.assertEquals(api_type[1], model_type[1]) @@ -92,8 +92,8 @@ class CreationTests(APISubdomainTestCase):  class DeletionTests(APISubdomainTestCase):      @classmethod      def setUpTestData(cls): -        cls.jpeg_format = AllowDenyList.objects.create(**JPEG_ALLOWLIST) -        cls.png_format = AllowDenyList.objects.create(**PNG_ALLOWLIST) +        cls.jpeg_format = FilterList.objects.create(**JPEG_ALLOWLIST) +        cls.png_format = FilterList.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 b6ed2914..a4fd5b2e 100644 --- a/pydis_site/apps/api/urls.py +++ b/pydis_site/apps/api/urls.py @@ -3,10 +3,10 @@ from rest_framework.routers import DefaultRouter  from .views import HealthcheckView, RulesView  from .viewsets import ( -    AllowDenyListViewSet,      BotSettingViewSet,      DeletedMessageViewSet,      DocumentationLinkViewSet, +    FilterListViewSet,      InfractionViewSet,      LogEntryViewSet,      NominationViewSet, @@ -18,12 +18,11 @@ from .viewsets import (      UserViewSet  ) -  # http://www.django-rest-framework.org/api-guide/routers/#defaultrouter  bot_router = DefaultRouter(trailing_slash=False)  bot_router.register( -    'allow_deny_lists', -    AllowDenyListViewSet +    'filter-lists', +    FilterListViewSet  )  bot_router.register(      'bot-settings', diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py index eb7d5098..8699517e 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 ( -    AllowDenyListViewSet, +    FilterListViewSet,      BotSettingViewSet,      DeletedMessageViewSet,      DocumentationLinkViewSet, diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index 11638dd8..e64e3988 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 .allow_deny_list import AllowDenyListViewSet +from .filter_list import FilterListViewSet  from .bot_setting import BotSettingViewSet  from .deleted_message import DeletedMessageViewSet  from .documentation_link import DocumentationLinkViewSet diff --git a/pydis_site/apps/api/viewsets/bot/allow_deny_list.py b/pydis_site/apps/api/viewsets/bot/filter_list.py index 6ea8da56..2cb21ab9 100644 --- a/pydis_site/apps/api/viewsets/bot/allow_deny_list.py +++ b/pydis_site/apps/api/viewsets/bot/filter_list.py @@ -3,17 +3,17 @@ from rest_framework.request import Request  from rest_framework.response import Response  from rest_framework.viewsets import ModelViewSet -from pydis_site.apps.api.models.bot.allow_deny_list import AllowDenyList -from pydis_site.apps.api.serializers import AllowDenyListSerializer +from pydis_site.apps.api.models.bot.filter_list import FilterList +from pydis_site.apps.api.serializers import FilterListSerializer -class AllowDenyListViewSet(ModelViewSet): +class FilterListViewSet(ModelViewSet):      """      View providing CRUD operations on items allowed or denied by our bot.      ## Routes -    ### GET /bot/allow_deny_lists -    Returns all allow and denylist items in the database. +    ### GET /bot/filter-lists +    Returns all filterlist items in the database.      #### Response format      >>> [ @@ -33,8 +33,8 @@ class AllowDenyListViewSet(ModelViewSet):      - 200: returned on success      - 401: returned if unauthenticated -    ### GET /bot/allow_deny_lists/<id:int> -    Returns a specific AllowDenyList item from the database. +    ### GET /bot/filter-lists/<id:int> +    Returns a specific FilterList item from the database.      #### Response format      >>> { @@ -51,7 +51,7 @@ class AllowDenyListViewSet(ModelViewSet):      - 200: returned on success      - 404: returned if the id was not found. -    ### GET /bot/allow_deny_lists/get_types +    ### GET /bot/filter-lists/get-types      Returns a list of valid list types that can be used in POST requests.      #### Response format @@ -65,8 +65,8 @@ class AllowDenyListViewSet(ModelViewSet):      #### Status codes      - 200: returned on success -    ### POST /bot/allow_deny_lists -    Adds a single AllowDenyList item to the database. +    ### POST /bot/filter-lists +    Adds a single FilterList item to the database.      #### Request body      >>> { @@ -80,18 +80,18 @@ class AllowDenyListViewSet(ModelViewSet):      - 201: returned on success      - 400: if one of the given fields is invalid -    ### DELETE /bot/allow_deny_lists/<id:int> -    Deletes the AllowDenyList item with the given `id`. +    ### DELETE /bot/filter-lists/<id:int> +    Deletes the FilterList item with the given `id`.      #### Status codes      - 204: returned on success      - 404: if a tag with the given `id` does not exist      """ -    serializer_class = AllowDenyListSerializer -    queryset = AllowDenyList.objects.all() +    serializer_class = FilterListSerializer +    queryset = FilterList.objects.all() -    @action(detail=False, methods=["get"]) +    @action(detail=False, url_path='get-types', methods=["get"])      def get_types(self, _: Request) -> Response: -        """Get a list of all the types of AllowDenyLists we support.""" -        return Response(AllowDenyList.AllowDenyListType.choices) +        """Get a list of all the types of FilterLists we support.""" +        return Response(FilterList.FilterListType.choices) | 
