mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 07:45:18 -05:00
feat: Implement centralized error capture and handling with new middleware, services, and API endpoints, and add new admin and statistics API views.
This commit is contained in:
@@ -20,6 +20,7 @@ from drf_spectacular.utils import (
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.accounts.models import PasswordReset
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
UserModel = get_user_model()
|
||||
|
||||
@@ -64,6 +65,7 @@ class UserOutputSerializer(serializers.ModelSerializer):
|
||||
|
||||
avatar_url = serializers.SerializerMethodField()
|
||||
display_name = serializers.SerializerMethodField()
|
||||
role = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = UserModel
|
||||
@@ -74,9 +76,12 @@ class UserOutputSerializer(serializers.ModelSerializer):
|
||||
"display_name",
|
||||
"date_joined",
|
||||
"is_active",
|
||||
"is_staff",
|
||||
"is_superuser",
|
||||
"role",
|
||||
"avatar_url",
|
||||
]
|
||||
read_only_fields = ["id", "date_joined", "is_active"]
|
||||
read_only_fields = ["id", "date_joined", "is_active", "is_staff", "is_superuser", "role"]
|
||||
|
||||
def get_display_name(self, obj):
|
||||
"""Get the user's display name."""
|
||||
@@ -89,6 +94,15 @@ class UserOutputSerializer(serializers.ModelSerializer):
|
||||
return obj.profile.get_avatar_url()
|
||||
return None
|
||||
|
||||
@extend_schema_field(serializers.CharField())
|
||||
def get_role(self, obj) -> str:
|
||||
"""Compute effective role based on permissions."""
|
||||
if obj.is_superuser:
|
||||
return "SUPERUSER"
|
||||
if obj.is_staff:
|
||||
return "ADMIN"
|
||||
return "USER"
|
||||
|
||||
|
||||
class LoginInputSerializer(serializers.Serializer):
|
||||
"""Input serializer for user login."""
|
||||
@@ -235,8 +249,8 @@ The ThrillWiki Team
|
||||
logger.info(f"Verification email sent successfully to {user.email}. No email ID in response.")
|
||||
|
||||
except Exception as e:
|
||||
# Log the error but don't fail registration
|
||||
logger.error(f"Failed to send verification email to {user.email}: {e}")
|
||||
# Capture error but don't fail registration
|
||||
capture_and_log(e, f'Send verification email to {user.email}', source='api', severity='low')
|
||||
|
||||
|
||||
class SignupOutputSerializer(serializers.Serializer):
|
||||
|
||||
Reference in New Issue
Block a user