diff --git a/backend/gn_module_export/send_mail.py b/backend/gn_module_export/send_mail.py deleted file mode 100644 index 4ff759f2..00000000 --- a/backend/gn_module_export/send_mail.py +++ /dev/null @@ -1,143 +0,0 @@ -""" - Fonctions permettant l'envoi d'email -""" -from flask import url_for, current_app - -from geonature.utils.utilsmails import send_mail - - -def export_send_mail(mail_to, export, file_name): - """ - Send email after export is done - - .. :quickref: Send email after export is done - - - :query [str] mail_to: User who runs the export - :query {} export: Export definition - :query str file_name: Name of exported file - """ - module_conf = current_app.config["EXPORTS"] - - if module_conf.get("export_web_url"): - url = "{}/{}".format(module_conf.get("export_web_url"), file_name) - else: - url = url_for( - "media", - filename=module_conf.get("usr_generated_dirname") + "/" + file_name, - _external=True, - ) - - msg = """ - Bonjour, -

- Votre export {} est accessible via le lien suivant : - Téléchargement. -

-

- Les données de cet export sont associées à la licence {}. - Merci de les utiliser en respectant cette licence. -

-

- Attention : Ce fichier sera supprimé sous {} jours. -

- """.format( - export["label"], - url, - export["licence"]["url_licence"], - export["licence"]["name_licence"], - str(current_app.config["EXPORTS"]["nb_days_keep_file"]), - ) - - send_mail( - recipients=mail_to, - subject="[GeoNature] Export {} réalisé".format(export["label"]), - msg_html=msg, - ) - - -def export_send_mail_error(mail_to, export, error): - """ - Send email after export is failed - - .. :quickref: Send email after export is failed - - - :query [str] mail_to: User who runs the export - :query {} export: Export definition - :query str error: Detail of the exception raised - - """ - - label = "" - if export: - label = export["label"] - - msg = """ - Bonjour, -

- Votre export {} n'a pas fonctionné correctement. -

-

- Detail : - {} -

-

- Veuillez signaler le problème à l'administrateur du site. -

- """.format( - label, error - ) - - # Si configuration de mail_on_error - # envoie d'un mail d'erreur à l'administrateur - if "ERROR_MAIL_TO" in current_app.config: - if ( - type(current_app.config["ERROR_MAIL_TO"]) is list - and current_app.config["ERROR_MAIL_TO"] - ): - export_send_admin_mail_error( - current_app.config["ERROR_MAIL_TO"], export, error - ) - - send_mail( - recipients=mail_to, - subject="[GeoNature][ERREUR] Export {}".format(label), - msg_html=msg, - ) - - -def export_send_admin_mail_error(mail_to, export, error): - """ - Send email after export has failed - - .. :quickref: Send email after export has failed - - - :query [str] role: User who runs the export - :query {} export: Export definition - :query str error: Detail of the exception raised - - """ - - label = "" - if export: - label = export["label"] - - msg = """ - Bonjour, -

- L'export {} n'a pas fonctionné correctement. -

-

- Detail : - {} -

- """.format( - label, error - ) - send_mail( - recipients=mail_to, - subject="[GeoNature-export][ERREUR] Export {}".format(label), - msg_html=msg, - ) diff --git a/backend/gn_module_export/utils_export.py b/backend/gn_module_export/utils_export.py index 6af52a1b..700df30d 100644 --- a/backend/gn_module_export/utils_export.py +++ b/backend/gn_module_export/utils_export.py @@ -17,7 +17,6 @@ from utils_flask_sqla_geo.utilsgeometry import FionaShapeService, FionaGpkgService from geonature.utils.filemanager import removeDisallowedFilenameChars -from .send_mail import export_send_mail, export_send_mail_error from geonature.utils.env import DB from geonature.core.notifications.utils import dispatch_notifications from .models import Export