Skip to content

Commit

Permalink
Moderation CheckUntested Code
Browse files Browse the repository at this point in the history
  • Loading branch information
AdvitRanawadePenn committed Nov 5, 2024
1 parent aea59b7 commit c890ef2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,15 @@ def create(self, request):
return Response(
{"message": "Insufficient fields provided."}, status=status.HTTP_400_BAD_REQUEST
)

# run moderation check
text = request.data.get("text")
flagged, moderation_results = check_text_moderation(text)
if flagged:
return Response(
{"message": "Comment flagged for moderation.", "moderation_results": moderation_results},
status=status.HTTP_400_BAD_REQUEST
)

# verify section is real
try:
Expand Down Expand Up @@ -1052,7 +1061,17 @@ def update(self, request, pk=None):
)

if "text" in request.data:
comment.text = request.data.get("text")
# Run moderation check on the new text
text = request.data.get("text")
flagged, moderation_results = check_text_moderation(text)
if flagged:
return Response(
{"message": "Comment flagged for moderation.", "moderation_results": moderation_results},
status=status.HTTP_400_BAD_REQUEST
)

# update and save comment
comment.text = text
comment.save()
return Response({"message": "Successfully edited."}, status=status.HTTP_201_CREATED)
else:
Expand Down

0 comments on commit c890ef2

Please sign in to comment.