From 54e6cc65db9d0cd91da332e3752c3da85b3c7a3f Mon Sep 17 00:00:00 2001 From: Evan Tung Date: Tue, 23 Apr 2024 20:14:23 -0400 Subject: [PATCH] use user_id as sentry set user id --- psychopass/views.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/psychopass/views.py b/psychopass/views.py index 19bdb97..17e13b6 100644 --- a/psychopass/views.py +++ b/psychopass/views.py @@ -14,14 +14,17 @@ @api_view(["POST"]) @permission_classes([IsAdminUser]) def ingest_message(request: Request) -> Response: - set_user({"id": request.user.id, "username": f"{request.user.username}/{request.data.get("userID")}"}) + set_user({ + "id": request.data.get("userID"), + "username": f"{request.user.username}/{request.data.get("userID")}" + }) psycho_pass, _ = UserPsychoPass.objects.get_or_create( platform=request.user, user_id=request.data.get("userID")) community = get_object_or_404( Community, platform=request.user, community_id=request.data.get("communityID")) community_psycho_pass = get_object_or_404( CommunityPsychoPass, community=community) - + attribute_scores = request.data["attributeScores"] psycho_pass.toxicity = psycho_pass.update_score( attribute_scores["TOXICITY"], psycho_pass.toxicity, psycho_pass.messages) @@ -38,7 +41,7 @@ def ingest_message(request: Request) -> Response: psycho_pass.sexually_explicit = psycho_pass.update_score( attribute_scores["SEXUALLY_EXPLICIT"], psycho_pass.sexually_explicit, psycho_pass.messages) psycho_pass.messages = max(0, min(500, psycho_pass.messages+1)) - + psycho_pass.save() community_psycho_pass.users.add(psycho_pass) community_psycho_pass.save() @@ -53,14 +56,20 @@ class UserPsychoPassView(APIView): permission_classes = [IsAdminUser] def get(self, request: Request) -> Response: - set_user({"id": request.user.id, "username": f"{request.user.username}/{request.query_params.get("id")}"}) + set_user({ + "id": request.query_params.get("id"), + "username": f"{request.user.username}/{request.query_params.get("id")}" + }) psycho_pass = get_object_or_404( UserPsychoPass, user_id=request.query_params.get("id")) return Response(UserPsychoPassSerializer(psycho_pass).data, status=status.HTTP_200_OK) def post(self, request: Request) -> Response: - set_user({"id": request.user.id, "username": f"{request.user.username}/{request.data.get("userID")}"}) + set_user({ + "id": request.data.get("userID"), + "username": f"{request.user.username}/{request.data.get("userID")}" + }) psycho_pass = UserPsychoPass.objects.create( platform=request.user, user_id=request.data.get("userID")) psycho_pass.save() @@ -68,7 +77,10 @@ def post(self, request: Request) -> Response: return Response(UserPsychoPassSerializer(psycho_pass).data, status=status.HTTP_201_CREATED) def delete(self, request: Request) -> Response: - set_user({"id": request.user.id, "username": f"{request.user.username}/{request.query_params.get("id")}"}) + set_user({ + "id": request.query_params.get("id"), + "username": f"{request.user.username}/{request.query_params.get("id")}" + }) psycho_pass = get_object_or_404( UserPsychoPass, user_id=request.query_params.get("id")) psycho_pass.delete()