mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-05 20:51:26 +00:00
fix: Suppression envoi mail / création page feedback
This commit is contained in:
@ -14,7 +14,7 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Profile
|
||||
fields = ['id', 'password', 'email', 'code', 'datePeremption', 'username', 'roles', 'roleIndexLoginDefault']
|
||||
fields = ['id', 'password', 'email', 'code', 'datePeremption', 'username', 'roles', 'roleIndexLoginDefault', 'first_name', 'last_name']
|
||||
extra_kwargs = {'password': {'write_only': True}}
|
||||
|
||||
def get_roles(self, obj):
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
from django.urls import path
|
||||
from .views import (
|
||||
SendEmailView, search_recipients
|
||||
SendEmailView, search_recipients, SendFeedbackView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('send-email/', SendEmailView.as_view(), name='send_email'),
|
||||
path('search-recipients/', search_recipients, name='search_recipients'),
|
||||
path('send-feedback/', SendFeedbackView.as_view(), name='send_feedback'),
|
||||
]
|
||||
@ -5,6 +5,7 @@ from rest_framework import status
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from django.db.models import Q
|
||||
from django.conf import settings
|
||||
from Auth.models import Profile, ProfileRole
|
||||
|
||||
import N3wtSchool.mailManager as mailer
|
||||
@ -119,3 +120,84 @@ def search_recipients(request):
|
||||
})
|
||||
|
||||
return JsonResponse(results, safe=False)
|
||||
|
||||
|
||||
class SendFeedbackView(APIView):
|
||||
"""
|
||||
API pour envoyer un feedback au support (EMAIL_HOST_USER).
|
||||
"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
data = request.data
|
||||
category = data.get('category', '')
|
||||
subject = data.get('subject', 'Feedback')
|
||||
message = data.get('message', '')
|
||||
user_email = data.get('user_email', '')
|
||||
user_name = data.get('user_name', '')
|
||||
establishment = data.get('establishment', {})
|
||||
|
||||
logger.info(f"Feedback received - Category: {category}, Subject: {subject}")
|
||||
|
||||
if not message or not subject or not category:
|
||||
return Response(
|
||||
{'error': 'La catégorie, le sujet et le message sont requis.'},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
try:
|
||||
# Construire le message formaté
|
||||
category_labels = {
|
||||
'bug': 'Signalement de bug',
|
||||
'feature': 'Proposition de fonctionnalité',
|
||||
'question': 'Question',
|
||||
'other': 'Autre'
|
||||
}
|
||||
category_label = category_labels.get(category, category)
|
||||
|
||||
# Construire les infos établissement
|
||||
establishment_id = establishment.get('id', 'N/A')
|
||||
establishment_name = establishment.get('name', 'N/A')
|
||||
establishment_capacity = establishment.get('total_capacity', 'N/A')
|
||||
establishment_frequency = establishment.get('evaluation_frequency', 'N/A')
|
||||
|
||||
formatted_message = f"""
|
||||
<h2>Nouveau Feedback - {category_label}</h2>
|
||||
<p><strong>De:</strong> {user_name} ({user_email})</p>
|
||||
<h3>Établissement</h3>
|
||||
<ul>
|
||||
<li><strong>ID:</strong> {establishment_id}</li>
|
||||
<li><strong>Nom:</strong> {establishment_name}</li>
|
||||
<li><strong>Capacité:</strong> {establishment_capacity}</li>
|
||||
<li><strong>Fréquence d'évaluation:</strong> {establishment_frequency}</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<p><strong>Sujet:</strong> {subject}</p>
|
||||
<div>
|
||||
<strong>Message:</strong><br>
|
||||
{message}
|
||||
</div>
|
||||
"""
|
||||
|
||||
formatted_subject = f"[N3WT School Feedback] [{category_label}] {subject}"
|
||||
|
||||
# Envoyer à EMAIL_HOST_USER avec la configuration SMTP par défaut
|
||||
result = mailer.sendMail(
|
||||
subject=formatted_subject,
|
||||
message=formatted_message,
|
||||
recipients=[settings.EMAIL_HOST_USER],
|
||||
cc=[],
|
||||
bcc=[],
|
||||
attachments=[],
|
||||
connection=None # Utilise la configuration SMTP par défaut
|
||||
)
|
||||
|
||||
logger.info("Feedback envoyé avec succès")
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Erreur lors de l'envoi du feedback: {str(e)}", exc_info=True)
|
||||
return Response(
|
||||
{'error': "Erreur lors de l'envoi du feedback"},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user