diff options
author | 2021-05-30 16:14:12 -0700 | |
---|---|---|
committer | 2021-05-30 16:14:12 -0700 | |
commit | 7a5a0321d8638d22d58112d8976d18fb07d7ce4e (patch) | |
tree | 8717dbd892d4f1e4693aa75b72c76bcc555aa00e /pydis_site/apps/api/viewsets | |
parent | Fix bot/infractions after and before filter check being inverted (diff) |
Ensure bot/infractions does not accept both expires and permanent filters
Expires and permanent=false are permitted and tested for. Expires_before also filters the database for permanent=false explicitly
Diffstat (limited to 'pydis_site/apps/api/viewsets')
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/infraction.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index 0baab6fd..f8b0cb9d 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -56,6 +56,7 @@ class InfractionViewSet( Invalid query parameters are ignored. Only one of `type` and `types` may be provided. If both `expires_before` and `expires_after` are provided, `expires_after` must come after `expires_before`. + If `permanent` is provided and true, `expires_before` and `expires_after` must not be provided. #### Response format Response is paginated but the result is returned without any pagination metadata. @@ -201,6 +202,23 @@ class InfractionViewSet( 'expires_after': ['cannot be before expires_before'], }) + if ( + ('expires_at__lte' in additional_filters or 'expires_at__gte' in additional_filters) + and 'expires_at__isnull' in additional_filters + and additional_filters['expires_at__isnull'] + ): + raise ValidationError({ + 'permanent': [ + 'cannot filter for permanent infractions at the' + ' same time as expires_at or expires_before', + ] + }) + + if filter_expires_before: + # Filter out permanent infractions specifically if we want ones that will expire + # before a given date + additional_filters['expires_at__isnull'] = False + filter_types = self.request.query_params.get('types') if filter_types: if self.request.query_params.get('type'): |