From 5a30d92cf86cbb7daa6f444f000e2c24f81bb7aa Mon Sep 17 00:00:00 2001
From: Axel Saint-maxin <axel.saintmaxin.etu@unvi-lille.fr>
Date: Tue, 25 Feb 2025 15:33:04 +0100
Subject: [PATCH] send mail to notify operations

---
 app/auth/models.py                          |  2 +-
 app/scodoc/sco_formsemestre_inscriptions.py | 22 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/app/auth/models.py b/app/auth/models.py
index 28933476..7020db17 100644
--- a/app/auth/models.py
+++ b/app/auth/models.py
@@ -630,7 +630,7 @@ class User(UserMixin, ScoDocModel):
 
     def get_nomcomplet(self):
         "Prénom et nom complets"
-        return "Tata Yoyoyoyo"
+        return scu.format_prenom(self.prenom) + " " + self.get_nom_fmt()
 
     # nomnoacc était le nom en minuscules sans accents (inutile)
 
diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py
index 9e932425..814e887a 100644
--- a/app/scodoc/sco_formsemestre_inscriptions.py
+++ b/app/scodoc/sco_formsemestre_inscriptions.py
@@ -57,6 +57,8 @@ from app.scodoc import sco_moduleimpl
 from app.scodoc import sco_groups
 from app.scodoc import sco_etud
 from app.scodoc import sco_cache
+from app.scodoc import sco_preferences
+from app import email
 
 
 # --- Gestion des inscriptions aux semestres
@@ -142,10 +144,28 @@ def do_formsemestre_demission(
     db.session.commit()
     sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
     if etat_new == scu.DEMISSION:
-        flash("Démission enregistrée")
+
+        etud = Identite.get_etud(etudid)
+        prefs = sco_preferences.SemPreferences(
+            formsemestre_id=formsemestre.id if formsemestre else None
+        )
+        destination = prefs["emails_notifications"] or ""
+        if (destination == ""):
+            str_mail_send = "aucune adresse mail disponible pour notifier les opérations dans le paramétrage"
+        else :
+            send_demission_mail(etud.__repr__(),destination)
+            str_mail_send = "mail pour notifier les opérations envoyer"
+        flash("Démission enregistrée, " + str_mail_send)
+
     elif etat_new == scu.DEF:
         flash("Défaillance enregistrée")
 
+def send_demission_mail(etud_info,destinations):
+    subject = "[ScoDoc] Notification de démission" 
+    sender = email.get_from_addr()
+    txt = "La démission de l'étudiant : " + etud_info + " à était réaliser avec succès"
+    email.send_email(subject, sender, destinations, txt)
+
 
 def do_formsemestre_inscription_edit(args=None, formsemestre_id=None):
     "edit a formsemestre_inscription"
-- 
GitLab