From cb5416bf54e512a66d36b72bff6f7b12a1c8cacd Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Wed, 15 Jul 2020 13:10:44 +0200 Subject: Allowlist viewset. https://github.com/python-discord/site/issues/305 --- pydis_site/apps/api/viewsets/bot/allowlist.py | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 pydis_site/apps/api/viewsets/bot/allowlist.py (limited to 'pydis_site') diff --git a/pydis_site/apps/api/viewsets/bot/allowlist.py b/pydis_site/apps/api/viewsets/bot/allowlist.py new file mode 100644 index 00000000..9b907d05 --- /dev/null +++ b/pydis_site/apps/api/viewsets/bot/allowlist.py @@ -0,0 +1,54 @@ +from rest_framework.viewsets import ModelViewSet + +from pydis_site.apps.api.models.bot.allowlist import AllowList +from pydis_site.apps.api.serializers import AllowListSerializer + + +class AllowListViewSet(ModelViewSet): + """ + View providing CRUD operations on items whitelisted or blacklisted by our bot. + + ## Routes + ### GET /bot/allowlists + Returns all allowlist items in the database. + + #### Response format + >>> [ + ... { + ... 'id': "2309268224", + ... 'created_at': "01-01-2020 ...", + ... 'updated_at': "01-01-2020 ...", + ... 'type': "file_format", + ... 'allowed': 'true', + ... 'content': ".jpeg", + ... }, + ... ... + ... ] + + #### Status codes + - 200: returned on success + + ### POST /bot/allowedlists + Adds a single allowedlist item to the database. + + #### Request body + >>> { + ... 'type': str, + ... 'allowed': bool, + ... 'content': str, + ... } + + #### Status codes + - 201: returned on success + - 400: if one of the given fields is invalid + + ### DELETE /bot/allowedlists/ + Deletes the tag with the given `title`. + + #### Status codes + - 204: returned on success + - 404: if a tag with the given `title` does not exist + """ + + serializer_class = AllowListSerializer + queryset = AllowList.objects.all() -- cgit v1.2.3