Corriger la suppression des mails Outlook
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
bfaf470c54
commit
a548612219
1 changed files with 14 additions and 8 deletions
|
|
@ -328,7 +328,7 @@ def data_management():
|
|||
"""Page de gestion des données : voir et supprimer en masse."""
|
||||
from ..models.maintenance import Intervention
|
||||
from ..models.equipment import Equipment
|
||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation
|
||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation, OutlookAttachment
|
||||
from ...ent.models import EntMessage
|
||||
from ...ent.interpretation_models import EntMessageInterpretation
|
||||
|
||||
|
|
@ -442,18 +442,24 @@ def delete_all_interventions():
|
|||
@admin_required
|
||||
def delete_all_mails():
|
||||
"""Supprime tous les mails Outlook."""
|
||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation
|
||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation, OutlookAttachment
|
||||
confirm = request.form.get('confirm_text', '')
|
||||
if confirm != 'SUPPRIMER':
|
||||
flash('Confirmation requise : tapez "SUPPRIMER" dans le champ de confirmation.', 'danger')
|
||||
return redirect(url_for('admin.data_management'))
|
||||
|
||||
# Supprimer d'abord les interpretations
|
||||
OutlookMailInterpretation.query.delete()
|
||||
# Supprimer les mails
|
||||
try:
|
||||
# Les pièces jointes possèdent une FK vers les mails : elles doivent
|
||||
# être supprimées avant leurs mails (le modèle seul ne garantit pas
|
||||
# une cascade côté MariaDB).
|
||||
OutlookAttachment.query.delete(synchronize_session=False)
|
||||
OutlookMailInterpretation.query.delete(synchronize_session=False)
|
||||
count = OutlookMail.query.count()
|
||||
OutlookMail.query.delete()
|
||||
OutlookMail.query.delete(synchronize_session=False)
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
raise
|
||||
flash(f'{count} mail(s) supprime(s) definitivement.', 'warning')
|
||||
return redirect(url_for('admin.data_management'))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue