Skip to content

Commit

Permalink
set user in sentry sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonejt committed Apr 24, 2024
1 parent 5ab1d83 commit d7ad1d6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions psychopass/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAdminUser
from rest_framework import status
from sentry_sdk import set_user
from community.models import Community
from psychopass.models import UserPsychoPass, UserPsychoPassSerializer, CommunityPsychoPass, CommunityPsychoPassSerializer
# Create your views here.
Expand All @@ -13,6 +14,7 @@
@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")}"})
psycho_pass, _ = UserPsychoPass.objects.get_or_create(
platform=request.user, user_id=request.data.get("userID"))
community = get_object_or_404(
Expand Down Expand Up @@ -51,19 +53,22 @@ 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")}"})
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")}"})
psycho_pass = UserPsychoPass.objects.create(
platform=request.user, user_id=request.data.get("userID"))
psycho_pass.save()

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")}"})
psycho_pass = get_object_or_404(
UserPsychoPass, user_id=request.query_params.get("id"))
psycho_pass.delete()
Expand Down

0 comments on commit d7ad1d6

Please sign in to comment.