Skip to content

Commit 46c89be

Browse files
Merge pull request #321 from bounswe/mehmetemin/blacklist
2 parents 9406857 + c269722 commit 46c89be

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

practice-app/backend/apps/events/api/v1/serializers.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from rest_framework import serializers
22
from apps.events.models import Event
3+
from django.conf import settings
34

45
class EventSerializer(serializers.ModelSerializer):
56
creator_username = serializers.ReadOnlyField(source='creator.username')
@@ -19,6 +20,31 @@ class Meta:
1920
]
2021
read_only_fields = ['creator', 'creator_username', 'participants_count', 'likes_count', 'created_at', 'updated_at']
2122

23+
## BLACKLISTED WORDS VALIDATION ##
24+
def validate(self, data):
25+
title = data.get("title", "")
26+
description = data.get("description", "")
27+
28+
banned = getattr(settings, "BLACKLISTED_WORDS", [])
29+
30+
lower_title = title.lower()
31+
lower_desc = description.lower()
32+
33+
for word in banned:
34+
w = word.lower()
35+
36+
if w in lower_title:
37+
raise serializers.ValidationError({
38+
"title": f"Title contains banned word: '{word}'"
39+
})
40+
41+
if w in lower_desc:
42+
raise serializers.ValidationError({
43+
"description": f"Description contains banned word: '{word}'"
44+
})
45+
46+
return data
47+
2248
def get_i_am_participating(self, obj):
2349
user = self.context['request'].user
2450
if user.is_anonymous:

practice-app/backend/config/settings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@
121121
}
122122
}
123123

124+
# Content Moderation Settings
125+
# List of blacklisted words for content moderation
126+
BLACKLISTED_WORDS = [
127+
"spam",
128+
"scam",
129+
"abuse",
130+
"violence",
131+
"hate",
132+
"drugs",
133+
]
134+
124135

125136
# Password validation
126137
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

0 commit comments

Comments
 (0)