From ce22f1e0a67f47aca48b5c548d7d1a544b9fe71d Mon Sep 17 00:00:00 2001 From: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> Date: Thu, 26 Sep 2019 16:30:12 +0200 Subject: Reject unhidden note or hidden warning infraction https://github.com/python-discord/site/issues/260 This commit adds validation steps to the InfractionSerializer to make sure that `"warning"` infractions can never be set with `hidden=True` and note infractions can never be set with `hidden=False` usng the API. This is the final step in decoupling "note" infractions and "warning" infractions. This commit implements the final part of and closes #260 --- pydis_site/apps/api/serializers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pydis_site/apps/api/serializers.py') diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 5466b06b..326e20e1 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -115,9 +115,12 @@ class InfractionSerializer(ModelSerializer): raise ValidationError({'expires_at': [f'{infr_type} infractions cannot expire.']}) hidden = attrs.get('hidden') - if hidden and infr_type in ('superstar',): + if hidden and infr_type in ('superstar', 'warning'): raise ValidationError({'hidden': [f'{infr_type} infractions cannot be hidden.']}) + if not hidden and infr_type in ('note', ): + raise ValidationError({'hidden': [f'{infr_type} infractions must be hidden.']}) + return attrs -- cgit v1.2.3