Skip to content

Commit

Permalink
Log des actions de modération
Browse files Browse the repository at this point in the history
  • Loading branch information
ggounot committed Dec 24, 2024
1 parent f671584 commit 8e9ca59
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions back/dora/structures/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from django.contrib import admin
from django.contrib.admin.filters import RelatedOnlyFieldListFilter
from django.forms.models import BaseInlineFormSet
Expand All @@ -20,6 +22,8 @@
StructureSource,
)

logger = logging.getLogger("dora.logs.core")


class StructurePutativeMemberAdmin(admin.ModelAdmin):
search_fields = (
Expand Down Expand Up @@ -300,14 +304,29 @@ def moderation_approve(self, request, object_id):
self.get_moderation_pending_structure_list_url()
)

moderation_pending_orientations = structure.orientations.filter(
status=OrientationStatus.MODERATION_PENDING
)

logger.info(
"Modération de structure : approbation",
{
"legal": False,
"userId": str(request.user.pk),
"userEmail": request.user.email,
"structureId": str(structure.pk),
"orientationIds": [
str(orientation.pk)
for orientation in moderation_pending_orientations
],
},
)

# Passage de la structure au statut de modération Validé
structure.moderation_status = ModerationStatus.VALIDATED
structure.save()

# Passage des demandes d'orientation en attente au statut Ouverte / En cours de traitement et envoi des e-mails
moderation_pending_orientations = structure.orientations.filter(
status=OrientationStatus.MODERATION_PENDING
)
for orientation in moderation_pending_orientations:
orientation.status = OrientationStatus.PENDING
orientation.save()
Expand Down Expand Up @@ -336,8 +355,34 @@ def moderation_reject(self, request, object_id):
self.get_moderation_pending_structure_list_url()
)

reason = request.POST.get("reason")

moderation_pending_orientations = structure.orientations.filter(
status=OrientationStatus.MODERATION_PENDING
)

logger.info(
"Modération de structure : rejet",
{
"legal": False,
"userId": str(request.user.pk),
"userEmail": request.user.email,
"structureId": str(structure.pk),
"orientationIds": [
str(orientation.pk)
for orientation in moderation_pending_orientations
],
"memberIds": [str(member.pk) for member in structure.members.all()],
"putativeMemberIds": [
str(putative_member.pk)
for putative_member in structure.putative_members.all()
],
"reason": reason,
},
)

# Envoi d'un e-mail explicatif à tous les membres et membres potentiels
send_moderation_rejected_notification(structure, request.POST.get("reason"))
send_moderation_rejected_notification(structure, reason)

# Désactivation de tous les membres et membres potentiels de la structure
structure.members.update(is_active=False)
Expand All @@ -353,9 +398,9 @@ def moderation_reject(self, request, object_id):
structure.save()

# Passage des demandes d'orientation en cours de modération au statut Supprimée par la modération
structure.orientations.filter(
status=OrientationStatus.MODERATION_PENDING
).update(status=OrientationStatus.MODERATION_REJECTED)
moderation_pending_orientations.update(
status=OrientationStatus.MODERATION_REJECTED
)

# Message de confirmation
self.message_user(
Expand Down

0 comments on commit 8e9ca59

Please sign in to comment.