aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/api/viewsets')
-rw-r--r--pydis_site/apps/api/viewsets/__init__.py2
-rw-r--r--pydis_site/apps/api/viewsets/bot/__init__.py5
-rw-r--r--pydis_site/apps/api/viewsets/bot/filter_list.py98
-rw-r--r--pydis_site/apps/api/viewsets/bot/filters.py499
4 files changed, 505 insertions, 99 deletions
diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py
index ec52416a..1dae9be1 100644
--- a/pydis_site/apps/api/viewsets/__init__.py
+++ b/pydis_site/apps/api/viewsets/__init__.py
@@ -6,6 +6,8 @@ from .bot import (
DocumentationLinkViewSet,
FilterListViewSet,
InfractionViewSet,
+ FilterListViewSet,
+ FilterViewSet,
NominationViewSet,
OffensiveMessageViewSet,
AocAccountLinkViewSet,
diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py
index 262aa59f..33b65009 100644
--- a/pydis_site/apps/api/viewsets/bot/__init__.py
+++ b/pydis_site/apps/api/viewsets/bot/__init__.py
@@ -1,5 +1,8 @@
# flake8: noqa
-from .filter_list import FilterListViewSet
+from .filters import (
+ FilterListViewSet,
+ FilterViewSet
+)
from .bot_setting import BotSettingViewSet
from .bumped_thread import BumpedThreadViewSet
from .deleted_message import DeletedMessageViewSet
diff --git a/pydis_site/apps/api/viewsets/bot/filter_list.py b/pydis_site/apps/api/viewsets/bot/filter_list.py
deleted file mode 100644
index 4b05acee..00000000
--- a/pydis_site/apps/api/viewsets/bot/filter_list.py
+++ /dev/null
@@ -1,98 +0,0 @@
-from rest_framework.decorators import action
-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.filter_list import FilterList
-from pydis_site.apps.api.serializers import FilterListSerializer
-
-
-class FilterListViewSet(ModelViewSet):
- """
- View providing CRUD operations on items allowed or denied by our bot.
-
- ## Routes
- ### GET /bot/filter-lists
- Returns all filterlist 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",
- ... 'comment': "Popular image format.",
- ... },
- ... ...
- ... ]
-
- #### Status codes
- - 200: returned on success
- - 401: returned if unauthenticated
-
- ### GET /bot/filter-lists/<id:int>
- Returns a specific FilterList item from the database.
-
- #### Response format
- >>> {
- ... 'id': "2309268224",
- ... 'created_at': "01-01-2020 ...",
- ... 'updated_at': "01-01-2020 ...",
- ... 'type': "file_format",
- ... 'allowed': 'true',
- ... 'content': ".jpeg",
- ... 'comment': "Popular image format.",
- ... }
-
- #### Status codes
- - 200: returned on success
- - 404: returned if the id was not found.
-
- ### GET /bot/filter-lists/get-types
- Returns a list of valid list types that can be used in POST requests.
-
- #### Response format
- >>> [
- ... ["GUILD_INVITE","Guild Invite"],
- ... ["FILE_FORMAT","File Format"],
- ... ["DOMAIN_NAME","Domain Name"],
- ... ["FILTER_TOKEN","Filter Token"],
- ... ["REDIRECT", "Redirect"]
- ... ]
-
- #### Status codes
- - 200: returned on success
-
- ### POST /bot/filter-lists
- Adds a single FilterList item to the database.
-
- #### Request body
- >>> {
- ... 'type': str,
- ... 'allowed': bool,
- ... 'content': str,
- ... 'comment': Optional[str],
- ... }
-
- #### Status codes
- - 201: returned on success
- - 400: if one of the given fields is invalid
-
- ### 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 = FilterListSerializer
- queryset = FilterList.objects.all()
-
- @action(detail=False, url_path='get-types', methods=["get"])
- def get_types(self, _: Request) -> Response:
- """Get a list of all the types of FilterLists we support."""
- return Response(FilterList.FilterListType.choices)
diff --git a/pydis_site/apps/api/viewsets/bot/filters.py b/pydis_site/apps/api/viewsets/bot/filters.py
new file mode 100644
index 00000000..d6c2d18c
--- /dev/null
+++ b/pydis_site/apps/api/viewsets/bot/filters.py
@@ -0,0 +1,499 @@
+from rest_framework.viewsets import ModelViewSet
+
+from pydis_site.apps.api.models.bot.filters import ( # noqa: I101 - Preserving the filter order
+ FilterList,
+ Filter
+)
+from pydis_site.apps.api.serializers import ( # noqa: I101 - Preserving the filter order
+ FilterListSerializer,
+ FilterSerializer,
+)
+
+
+class FilterListViewSet(ModelViewSet):
+ """
+ View providing GET/DELETE on lists of items allowed or denied by our bot.
+
+ ## Routes
+ ### GET /bot/filter/filter_lists
+ Returns all FilterList items in the database.
+
+ #### Response format
+ >>> [
+ ... {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.027293Z",
+ ... "updated_at": "2023-01-27T21:26:34.027308Z",
+ ... "name": "invite",
+ ... "list_type": 1,
+ ... "filters": [
+ ... {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... },
+ ... ...
+ ... ],
+ ... "settings": {
+ ... "bypass_roles": [
+ ... "Helpers"
+ ... ],
+ ... "filter_dm": True,
+ ... "enabled": True,
+ ... "remove_context": True,
+ ... "send_alert": True,
+ ... "infraction_and_notification": {
+ ... "infraction_type": "NONE",
+ ... "infraction_reason": "",
+ ... "infraction_duration": "0.0",
+ ... "infraction_channel": 0,
+ ... "dm_content": "Per Rule 6, your invite link has been removed...",
+ ... "dm_embed": ""
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": [],
+ ... "disabled_categories": [
+ ... "CODE JAM"
+ ... ],
+ ... "enabled_channels": [],
+ ... "enabled_categories": []
+ ... },
+ ... "mentions": {
+ ... "guild_pings": [
+ ... "Moderators"
+ ... ],
+ ... "dm_pings": []
+ ... }
+ ... }
+ ... },
+ ... ...
+ ... ]
+
+ #### Status codes
+ - 200: returned on success
+ - 401: returned if unauthenticated
+
+ ### GET /bot/filter/filter_lists/<id:int>
+ Returns a specific FilterList item from the database.
+
+ #### Response format
+ >>> {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.027293Z",
+ ... "updated_at": "2023-01-27T21:26:34.027308Z",
+ ... "name": "invite",
+ ... "list_type": 1,
+ ... "filters": [
+ ... {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... },
+ ... ...
+ ... ],
+ ... "settings": {
+ ... "bypass_roles": [
+ ... "Helpers"
+ ... ],
+ ... "filter_dm": True,
+ ... "enabled": True,
+ ... "remove_context": True,
+ ... "send_alert": True,
+ ... "infraction_and_notification": {
+ ... "infraction_type": "NONE",
+ ... "infraction_reason": "",
+ ... "infraction_duration": "0.0",
+ ... "infraction_channel": 0,
+ ... "dm_content": "Per Rule 6, your invite link has been removed...",
+ ... "dm_embed": ""
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": [],
+ ... "disabled_categories": [
+ ... "CODE JAM"
+ ... ],
+ ... "enabled_channels": [],
+ ... "enabled_categories": []
+ ... },
+ ... "mentions": {
+ ... "guild_pings": [
+ ... "Moderators"
+ ... ],
+ ... "dm_pings": []
+ ... }
+ ... }
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 404: returned if the id was not found.
+
+ ### POST /bot/filter/filter_lists
+ Adds a single FilterList item to the database.
+
+ #### Request body
+ >>> {
+ ... "name": "invite",
+ ... "list_type": 1,
+ ... "bypass_roles": [
+ ... "Helpers"
+ ... ],
+ ... "filter_dm": True,
+ ... "enabled": True,
+ ... "remove_context": True,
+ ... "send_alert": True,
+ ... "infraction_type": "NONE",
+ ... "infraction_reason": "",
+ ... "infraction_duration": "0.0",
+ ... "infraction_channel": 0,
+ ... "dm_content": "Per Rule 6, your invite link has been removed...",
+ ... "dm_embed": "",
+ ... "disabled_channels": [],
+ ... "disabled_categories": [
+ ... "CODE JAM"
+ ... ],
+ ... "enabled_channels": [],
+ ... "enabled_categories": []
+ ... "guild_pings": [
+ ... "Moderators"
+ ... ],
+ ... "dm_pings": []
+ ... }
+
+ #### Status codes
+ - 201: returned on success
+ - 400: if one of the given fields is invalid
+
+ ### PATCH /bot/filter/filter_lists/<id:int>
+ Updates a specific FilterList item from the database.
+
+ #### Response format
+ >>> {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.027293Z",
+ ... "updated_at": "2023-01-27T21:26:34.027308Z",
+ ... "name": "invite",
+ ... "list_type": 1,
+ ... "filters": [
+ ... {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... },
+ ... ...
+ ... ],
+ ... "settings": {
+ ... "bypass_roles": [
+ ... "Helpers"
+ ... ],
+ ... "filter_dm": True,
+ ... "enabled": True,
+ ... "remove_context": True,
+ ... "send_alert": True,
+ ... "infraction_and_notification": {
+ ... "infraction_type": "NONE",
+ ... "infraction_reason": "",
+ ... "infraction_duration": "0.0",
+ ... "infraction_channel": 0,
+ ... "dm_content": "Per Rule 6, your invite link has been removed...",
+ ... "dm_embed": ""
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": [],
+ ... "disabled_categories": [
+ ... "CODE JAM"
+ ... ],
+ ... "enabled_channels": [],
+ ... "enabled_categories": []
+ ... },
+ ... "mentions": {
+ ... "guild_pings": [
+ ... "Moderators"
+ ... ],
+ ... "dm_pings": []
+ ... }
+ ... }
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 400: if one of the given fields is invalid
+
+ ### DELETE /bot/filter/filter_lists/<id:int>
+ Deletes the FilterList item with the given `id`.
+
+ #### Status codes
+ - 204: returned on success
+ - 404: if a FilterList with the given `id` does not exist
+ """
+
+ serializer_class = FilterListSerializer
+ queryset = FilterList.objects.all()
+
+
+class FilterViewSet(ModelViewSet):
+ """
+ View providing CRUD operations on items allowed or denied by our bot.
+
+ ## Routes
+ ### GET /bot/filter/filters
+ Returns all Filter items in the database.
+
+ #### Response format
+ >>> [
+ ... {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... },
+ ... ...
+ ... ]
+
+ #### Status codes
+ - 200: returned on success
+ - 401: returned if unauthenticated
+
+ ### GET /bot/filter/filters/<id:int>
+ Returns a specific Filter item from the database.
+
+ #### Response format
+ >>> {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 404: returned if the id was not found.
+
+ ### POST /bot/filter/filters
+ Adds a single Filter item to the database.
+
+ #### Request body
+ >>> {
+ ... "filter_list": 1,
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": False,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+
+ #### Status codes
+ - 201: returned on success
+ - 400: if one of the given fields is invalid
+
+ ### PATCH /bot/filter/filters/<id:int>
+ Updates a specific Filter item from the database.
+
+ #### Response format
+ >>> {
+ ... "id": 1,
+ ... "created_at": "2023-01-27T21:26:34.029539Z",
+ ... "updated_at": "2023-01-27T21:26:34.030532Z",
+ ... "content": "267624335836053506",
+ ... "description": "Python Discord",
+ ... "additional_settings": None,
+ ... "filter_list": 1,
+ ... "settings": {
+ ... "bypass_roles": None,
+ ... "filter_dm": None,
+ ... "enabled": None,
+ ... "remove_context": None,
+ ... "send_alert": None,
+ ... "infraction_and_notification": {
+ ... "infraction_type": None,
+ ... "infraction_reason": None,
+ ... "infraction_duration": None,
+ ... "infraction_channel": None,
+ ... "dm_content": None,
+ ... "dm_embed": None
+ ... },
+ ... "channel_scope": {
+ ... "disabled_channels": None,
+ ... "disabled_categories": None,
+ ... "enabled_channels": None,
+ ... "enabled_categories": None
+ ... },
+ ... "mentions": {
+ ... "guild_pings": None,
+ ... "dm_pings": None
+ ... }
+ ... }
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 400: if one of the given fields is invalid
+
+ ### DELETE /bot/filter/filters/<id:int>
+ Deletes the Filter item with the given `id`.
+
+ #### Status codes
+ - 204: returned on success
+ - 404: if a Filter with the given `id` does not exist
+ """
+
+ serializer_class = FilterSerializer
+ queryset = Filter.objects.all()