diff options
Diffstat (limited to 'pydis_site')
| -rw-r--r-- | pydis_site/apps/api/models/__init__.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/api/models/bot/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 84 | ||||
| -rw-r--r-- | pydis_site/apps/api/urls.py | 20 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/__init__.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 6 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/filters.py | 450 | 
7 files changed, 15 insertions, 555 deletions
diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py index 72f59b57..63087990 100644 --- a/pydis_site/apps/api/models/__init__.py +++ b/pydis_site/apps/api/models/__init__.py @@ -1,11 +1,7 @@  # flake8: noqa  from .bot import (      FilterList, -    FilterSettings, -    FilterAction, -    ChannelRange,      Filter, -    FilterOverride,      BotSetting,      DocumentationLink,      DeletedMessage, diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py index 1bfe0063..9ba763a4 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 .filters import FilterList, FilterSettings, FilterAction, ChannelRange, Filter, FilterOverride +from .filters import FilterList, Filter  from .bot_setting import BotSetting  from .deleted_message import DeletedMessage  from .documentation_link import DocumentationLink diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index afcf4d55..ff2bd929 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -18,11 +18,7 @@ from .models import (  # noqa: I101 - Preserving the filter order      DocumentationLink,      Infraction,      FilterList, -    FilterSettings, -    FilterAction, -    ChannelRange,      Filter, -    FilterOverride,      MessageDeletionContext,      Nomination,      NominationEntry, @@ -136,7 +132,18 @@ class FilterListSerializer(ModelSerializer):          """Metadata defined for the Django REST Framework."""          model = FilterList -        fields = ('id', 'name', 'list_type', 'filters', 'default_settings') +        fields = ( +            'id', +            'name', +            'list_type', +            'filters', +            'ping_type', +            'filter_dm', +            'dm_ping_type', +            'delete_messages', +            'bypass_roles', +            '' +        )          # Ensure that we can only have one filter list with the same name and field          validators = [ @@ -150,73 +157,6 @@ class FilterListSerializer(ModelSerializer):          ] -class FilterSettingsSerializer(ModelSerializer): -    """A class providing (de-)serialization of `FilterSettings` instances.""" - -    class Meta: -        """Metadata defined for the Django REST Framework.""" - -        model = FilterSettings -        fields = ( -            'id', -            'ping_type', -            'filter_dm', -            'dm_ping_type', -            'delete_messages', -            'bypass_roles', -            'enabled', -            'default_action', -            'default_range' -        ) - - -class FilterActionSerializer(ModelSerializer): -    """A class providing (de-)serialization of `FilterAction` instances.""" - -    class Meta: -        """Metadata defined for the Django REST Framework.""" - -        model = FilterAction -        fields = ('id', 'dm_content', 'infraction_type', 'infraction_reason', 'infraction_duration') - - -class FilterChannelRangeSerializer(ModelSerializer): -    """A class providing (de-)serialization of `ChannelRange` instances.""" - -    class Meta: -        """Metadata defined for the Django REST Framework.""" - -        model = ChannelRange -        fields = ( -            'id', -            'disallowed_channels', -            'disallowed_categories', -            'allowed_channels', -            'allowed_categories', -            'default' -        ) - - -class FilterOverrideSerializer(ModelSerializer): -    """A class providing (de-)serialization of `FilterOverride` instances.""" - -    class Meta: -        """Metadata defined for the Django REST Framework.""" - -        model = FilterOverride -        fields = ( -            'id', -            'ping_type', -            'filter_dm', -            'dm_ping_type', -            'delete_messages', -            'bypass_roles', -            'enabled', -            'filter_action', -            'filter_range' -        ) - -  class InfractionSerializer(ModelSerializer):      """A class providing (de-)serialization of `Infraction` instances.""" diff --git a/pydis_site/apps/api/urls.py b/pydis_site/apps/api/urls.py index 7af2e505..4e8edaf0 100644 --- a/pydis_site/apps/api/urls.py +++ b/pydis_site/apps/api/urls.py @@ -7,11 +7,7 @@ from .viewsets import (  # noqa: I101 - Preserving the filter order      DeletedMessageViewSet,      DocumentationLinkViewSet,      FilterListViewSet, -    FilterSettingsViewSet, -    FilterActionViewSet, -    FilterChannelRangeViewSet,      FilterViewSet, -    FilterOverrideViewSet,      InfractionViewSet,      NominationViewSet,      OffTopicChannelNameViewSet, @@ -28,22 +24,6 @@ bot_router.register(      FilterListViewSet  )  bot_router.register( -    'filter/filter_settings', -    FilterSettingsViewSet -) -bot_router.register( -    'filter/filter_action', -    FilterActionViewSet -) -bot_router.register( -    'filter/channel_range', -    FilterChannelRangeViewSet -) -bot_router.register( -    'filter/filter_override', -    FilterOverrideViewSet -) -bot_router.register(      'filter/filters',      FilterViewSet  ) diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py index b3992d66..4cf4c655 100644 --- a/pydis_site/apps/api/viewsets/__init__.py +++ b/pydis_site/apps/api/viewsets/__init__.py @@ -5,11 +5,7 @@ from .bot import (      DocumentationLinkViewSet,      InfractionViewSet,      FilterListViewSet, -    FilterSettingsViewSet, -    FilterActionViewSet, -    FilterChannelRangeViewSet,      FilterViewSet, -    FilterOverrideViewSet,      NominationViewSet,      OffensiveMessageViewSet,      OffTopicChannelNameViewSet, diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index 781624bd..4649fcde 100644 --- a/pydis_site/apps/api/viewsets/bot/__init__.py +++ b/pydis_site/apps/api/viewsets/bot/__init__.py @@ -1,11 +1,7 @@  # flake8: noqa  from .filters import (      FilterListViewSet, -    FilterSettingsViewSet, -    FilterActionViewSet, -    FilterChannelRangeViewSet, -    FilterViewSet, -    FilterOverrideViewSet +    FilterViewSet  )  from .bot_setting import BotSettingViewSet  from .deleted_message import DeletedMessageViewSet diff --git a/pydis_site/apps/api/viewsets/bot/filters.py b/pydis_site/apps/api/viewsets/bot/filters.py index 1b893f8c..5b21de26 100644 --- a/pydis_site/apps/api/viewsets/bot/filters.py +++ b/pydis_site/apps/api/viewsets/bot/filters.py @@ -2,19 +2,11 @@ from rest_framework.viewsets import ModelViewSet  from pydis_site.apps.api.models.bot.filters import (  # noqa: I101 - Preserving the filter order      FilterList, -    FilterSettings, -    FilterAction, -    ChannelRange, -    Filter, -    FilterOverride +    Filter  )  from pydis_site.apps.api.serializers import (  # noqa: I101 - Preserving the filter order      FilterListSerializer, -    FilterSettingsSerializer, -    FilterActionSerializer, -    FilterChannelRangeSerializer,      FilterSerializer, -    FilterOverrideSerializer  ) @@ -90,311 +82,6 @@ class FilterListViewSet(ModelViewSet):      queryset = FilterList.objects.all() -class FilterSettingsViewSet(ModelViewSet): -    """ -    View providing CRUD operations on settings of items allowed or denied by our bot. - -    ## Routes -    ### GET /bot/filter/filter_settings -    Returns all FilterSettings items in the database. - -    #### Response format -    >>> [ -    ...     { -    ...         "id": 1, -    ...         "ping_type": [ -    ...             "onduty", -    ...              ... -    ...          ], -    ...         "filter_dm": True, -    ...         "dm_ping_type": [ -    ...             "onduty", -    ...             ... -    ...         ], -    ...         "delete_messages": True, -    ...         "bypass_roles": [ -    ...             267630620367257601, -    ...             ... -    ...         ], -    ...         "enabled": True, -    ...         "default_action": 1, -    ...         "default_range": 1 -    ...     }, -    ...     ... -    ... ] - -    #### Status codes -    - 200: returned on success -    - 401: returned if unauthenticated - -    ### GET /bot/filter/filter_settings/<id:int> -    Returns a specific FilterSettings item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "default_action": 1, -    ...     "default_range": 1 -    ... } - -    #### Status codes -    - 200: returned on success -    - 404: returned if the id was not found. - -    ### POST /bot/filter/filter_settings -    Adds a single FilterSettings item to the database. - -    #### Request body -    >>> { -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "default_action": 1, -    ...     "default_range": 1 -    ... } - -    #### Status codes -    - 201: returned on success -    - 400: if one of the given fields is invalid - -    ### PATCH /bot/filter/filter_settings/<id:int> -    Updates a specific FilterSettings item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "default_action": 1, -    ...     "default_range": 1 -    ... } - -    #### Status codes -    - 200: returned on success -    - 400: if one of the given fields is invalid - -    ### DELETE /bot/filter/filter_settings/<id:int> -    Deletes the FilterSettings item with the given `id`. - -    #### Status codes -    - 204: returned on success -    - 404: if a tag with the given `id` does not exist -    """ - -    serializer_class = FilterSettingsSerializer -    queryset = FilterSettings.objects.all() - - -class FilterActionViewSet(ModelViewSet): -    """ -    View providing CRUD operations on actions taken by items allowed or denied by our bot. - -    ## Routes -    ### GET /bot/filter/filter_action -    Returns all FilterAction items in the database. - -    #### Response format -    >>> [ -    ...     { -    ...         "id": 1, -    ...         "dm_content": "message", -    ...         "infraction_type": "Warn", -    ...         "infraction_reason": "", -    ...         "infraction_duration": "01 12:34:56.123456" -    ...     }, -    ...     ... -    ... ] - -    #### Status codes -    - 200: returned on success -    - 401: returned if unauthenticated - -    ### GET /bot/filter/filter_action/<id:int> -    Returns a specific FilterAction item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "dm_content": "message", -    ...     "infraction_type": "Warn", -    ...     "infraction_reason": "", -    ...     "infraction_duration": "01 12:34:56.123456" -    ... } - -    #### Status codes -    - 200: returned on success -    - 404: returned if the id was not found. - -    ### POST /bot/filter/filter_action -    Adds a single FilterAction item to the database. - -    #### Request body -    >>> { -    ...     "dm_content": "message", -    ...     "infraction_type": "Warn", -    ...     "infraction_reason": "", -    ...     "infraction_duration": "01 12:34:56.123456" -    ... } - -    #### Status codes -    - 201: returned on success -    - 400: if one of the given fields is invalid - -    ### PATCH /bot/filter/filter_action/<id:int> -    Updates a specific FilterAction item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "dm_content": "message", -    ...     "infraction_type": "Warn", -    ...     "infraction_reason": "", -    ...     "infraction_duration": "01 12:34:56.123456" -    ... } - -    #### Status codes -    - 200: returned on success -    - 400: if one of the given fields is invalid - -    ### DELETE /bot/filter/filter_action/<id:int> -    Deletes the FilterAction item with the given `id`. - -    #### Status codes -    - 204: returned on success -    - 404: if a tag with the given `id` does not exist -    """ - -    serializer_class = FilterActionSerializer -    queryset = FilterAction.objects.all() - - -class FilterChannelRangeViewSet(ModelViewSet): -    """ -    View providing CRUD operations on channels targeted by items allowed or denied by our bot. - -    ## Routes -    ### GET /bot/filter/channel_range -    Returns all ChannelRange items in the database. - -    #### Response format -    >>> [ -    ...     { -    ...         "id": 1, -    ...         "disallowed_channels": [], -    ...         "disallowed_categories": [], -    ...         "allowed_channels": [], -    ...         "allowed_categories": [], -    ...         "default": True -    ...     }, -    ...     ... -    ... ] - -    #### Status codes -    - 200: returned on success -    - 401: returned if unauthenticated - -    ### GET /bot/filter/channel_range/<id:int> -    Returns a specific ChannelRange item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "disallowed_channels": [], -    ...     "disallowed_categories": [], -    ...     "allowed_channels": [], -    ...     "allowed_categories": [], -    ...     "default": True -    ... } - -    #### Status codes -    - 200: returned on success -    - 404: returned if the id was not found. - -    ### POST /bot/filter/channel_range -    Adds a single ChannelRange item to the database. - -    #### Request body -    >>> { -    ...     "disallowed_channels": [], -    ...     "disallowed_categories": [], -    ...     "allowed_channels": [], -    ...     "allowed_categories": [], -    ...     "default": True -    ... } - -    #### Status codes -    - 201: returned on success -    - 400: if one of the given fields is invalid - -    ### PATCH /bot/filter/channel_range/<id:int> -    Updates a specific ChannelRange item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "disallowed_channels": [], -    ...     "disallowed_categories": [], -    ...     "allowed_channels": [], -    ...     "allowed_categories": [], -    ...     "default": True -    ... } - -    #### Status codes -    - 200: returned on success -    - 400: if one of the given fields is invalid - -    ### DELETE /bot/filter/channel_range/<id:int> -    Deletes the ChannelRange item with the given `id`. - -    #### Status codes -    - 204: returned on success -    - 404: if a tag with the given `id` does not exist -    """ - -    serializer_class = FilterChannelRangeSerializer -    queryset = ChannelRange.objects.all() - -  class FilterViewSet(ModelViewSet):      """      View providing CRUD operations on items allowed or denied by our bot. @@ -477,138 +164,3 @@ class FilterViewSet(ModelViewSet):      serializer_class = FilterSerializer      queryset = Filter.objects.all() - - -class FilterOverrideViewSet(ModelViewSet): -    """ -    View providing CRUD operations setting overrides of items allowed or denied by our bot. - -    ## Routes -    ### GET /bot/filter/filter_override -    Returns all FilterOverride items in the database. - -    #### Response format -    >>> [ -    ...     { -    ...         "id": 1, -    ...         "ping_type": [ -    ...             "onduty", -    ...              ... -    ...          ], -    ...         "filter_dm": True, -    ...         "dm_ping_type": [ -    ...             "onduty", -    ...             ... -    ...         ], -    ...         "delete_messages": True, -    ...         "bypass_roles": [ -    ...             267630620367257601, -    ...             ... -    ...         ], -    ...         "enabled": True, -    ...         "filter_action": 1, -    ...         "filter_range": 1 -    ...     }, -    ...     ... -    ... ] - -    #### Status codes -    - 200: returned on success -    - 401: returned if unauthenticated - -    ### GET /bot/filter/filter_override/<id:int> -    Returns a specific FilterOverride item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "filter_action": 1, -    ...     "filter_range": 1 -    ... } - -    #### Status codes -    - 200: returned on success -    - 404: returned if the id was not found. - -    ### POST /bot/filter/filter_override -    Adds a single FilterOverride item to the database. - -    #### Request body -    >>> { -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "filter_action": 1, -    ...     "filter_range": 1 -    ... } - -    #### Status codes -    - 201: returned on success -    - 400: if one of the given fields is invalid - -    ### PATCH /bot/filter/filter_override/<id:int> -    Updates a specific FilterOverride item from the database. - -    #### Response format -    >>> { -    ...     "id": 1, -    ...     "ping_type": [ -    ...         "onduty", -    ...          ... -    ...     ], -    ...     "filter_dm": True, -    ...     "dm_ping_type": [ -    ...         "onduty", -    ...         ... -    ...     ], -    ...     "delete_messages": True, -    ...     "bypass_roles": [ -    ...         267630620367257601, -    ...         ... -    ...     ], -    ...     "enabled": True, -    ...     "filter_action": 1, -    ...     "filter_range": 1 -    ... } - -    #### Status codes -    - 200: returned on success -    - 400: if one of the given fields is invalid - -    ### DELETE /bot/filter/filter_override/<id:int> -    Deletes the FilterOverride item with the given `id`. - -    #### Status codes -    - 204: returned on success -    - 404: if a tag with the given `id` does not exist -    """ - -    serializer_class = FilterOverrideSerializer -    queryset = FilterOverride.objects.all()  |