aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pydis_site/apps/api/serializers.py17
-rw-r--r--pydis_site/apps/api/viewsets/bot/filters.py49
2 files changed, 60 insertions, 6 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index 864ab52e..267cf761 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -181,7 +181,7 @@ class FilterSerializer(ModelSerializer):
model = Filter
fields = (
'id', 'content', 'description', 'additional_field', 'filter_list'
- ) + SETTINGS_FIELDS
+ )
extra_kwargs = {
field: {'required': False, 'allow_null': True} for field in SETTINGS_FIELDS
} | {
@@ -194,7 +194,8 @@ class FilterSerializer(ModelSerializer):
def to_representation(self, instance: Filter) -> dict:
"""
- Provides a custom JSON representation to the Filter Serializers
+
+ Provides a custom JSON representation to the Filter Serializers.
That does not affect how the Serializer works in general.
"""
@@ -239,7 +240,7 @@ class FilterListSerializer(ModelSerializer):
"""Metadata defined for the Django REST Framework."""
model = FilterList
- fields = ('id', 'name', 'list_type', 'filters') + SETTINGS_FIELDS
+ fields = ('id', 'name', 'list_type', 'filters')
extra_kwargs = {
field: {'required': False, 'allow_null': True} for field in ALWAYS_OPTIONAL_SETTINGS
} | {
@@ -261,6 +262,16 @@ class FilterListSerializer(ModelSerializer):
),
]
+ def to_representation(self, instance: FilterList) -> dict:
+ """
+ Provides a custom JSON representation to the FilterList Serializers.
+
+ That does not affect how the Serializer works in general.
+ """
+ ret = super().to_representation(instance)
+ ret["settings"] = {name: getattr(instance, name) for name in SETTINGS_FIELDS}
+ return ret
+
class InfractionSerializer(ModelSerializer):
"""A class providing (de-)serialization of `Infraction` instances."""
diff --git a/pydis_site/apps/api/viewsets/bot/filters.py b/pydis_site/apps/api/viewsets/bot/filters.py
index 64329ebe..cbadcf2b 100644
--- a/pydis_site/apps/api/viewsets/bot/filters.py
+++ b/pydis_site/apps/api/viewsets/bot/filters.py
@@ -52,7 +52,28 @@ class FilterListViewSet(ModelViewSet):
... },
... ...
... ],
- ... "default_settings": 1
+ ... "settings": {
+ ... "dm_content": None,
+ ... "infraction_type": None,
+ ... "infraction_reason": "",
+ ... "infraction_duration": None,
+ ... "ping_type": [
+ ... "onduty"
+ ... ],
+ ... "filter_dm": True,
+ ... "dm_ping_type": [
+ ... "onduty"
+ ... ],
+ ... "delete_messages": True,
+ ... "bypass_roles": [
+ ... 267630620367257601
+ ... ],
+ ... "enabled": False,
+ ... "disallowed_channels": [],
+ ... "disallowed_categories": [],
+ ... "allowed_channels": [],
+ ... "allowed_categories": []
+ ... }
... },
... ...
... ]
@@ -65,6 +86,7 @@ class FilterListViewSet(ModelViewSet):
Returns a specific FilterList item from the database.
#### Response format
+ >>>
... {
... "id": 1,
... "name": "guild_invite",
@@ -95,9 +117,30 @@ class FilterListViewSet(ModelViewSet):
... }
...
... },
- ... ...
+ ...
... ],
- ... "default_settings": 1
+ ... "settings": {
+ ... "dm_content": None,
+ ... "infraction_type": None,
+ ... "infraction_reason": "",
+ ... "infraction_duration": None,
+ ... "ping_type": [
+ ... "onduty"
+ ... ],
+ ... "filter_dm": True,
+ ... "dm_ping_type": [
+ ... "onduty"
+ ... ],
+ ... "delete_messages": True,
+ ... "bypass_roles": [
+ ... 267630620367257601
+ ... ],
+ ... "enabled": False,
+ ... "disallowed_channels": [],
+ ... "disallowed_categories": [],
+ ... "allowed_channels": [],
+ ... "allowed_categories": []
+ ... }
... }
#### Status codes