diff --git a/lemarche/api/emails/views.py b/lemarche/api/emails/views.py index 2b6cbba84..e451ddb91 100644 --- a/lemarche/api/emails/views.py +++ b/lemarche/api/emails/views.py @@ -5,6 +5,7 @@ from rest_framework.views import APIView from lemarche.api.emails.serializers import EmailsSerializer +from lemarche.conversations.constants import ATTRIBUTES_TO_SAVE_FOR_INBOUND from lemarche.conversations.models import Conversation from lemarche.conversations.utils import get_info_from_email_prefix from lemarche.www.conversations.tasks import send_email_from_conversation @@ -13,6 +14,21 @@ logger = logging.getLogger(__name__) +def clean_saved_data_of_inbound(data_inbound: dict): + """We clean saved data to respect the law of RGPD + + Args: + data_inbound (dict): all data that we receive from inbound api + + Returns: + dict with only neccessary key to save + """ + clean_saved_data = {} + for key in ATTRIBUTES_TO_SAVE_FOR_INBOUND: + clean_saved_data[key] = data_inbound.get(key) + return clean_saved_data + + class InboundParsingEmailView(APIView): def post(self, request): serializer = EmailsSerializer(data=request.data) @@ -23,7 +39,8 @@ def post(self, request): version, conv_uuid, user_kind = get_info_from_email_prefix(inbound_email_prefix) conv: Conversation = Conversation.objects.get_conv_from_uuid(conv_uuid=conv_uuid, version=version) # save the input data - conv.data.append(serializer.data) + data_inbound_clean = clean_saved_data_of_inbound(data_inbound=serializer.data.get("items")[0]) + conv.data.append(data_inbound_clean) conv.save() # find user_kind if version >= 1: diff --git a/lemarche/conversations/constants.py b/lemarche/conversations/constants.py new file mode 100644 index 000000000..e56280a17 --- /dev/null +++ b/lemarche/conversations/constants.py @@ -0,0 +1 @@ +ATTRIBUTES_TO_SAVE_FOR_INBOUND = ["From", "To", "CC", "ReplyTo", "SentAtDate", "Attachments"] diff --git a/lemarche/static/js/filter_data_message.js b/lemarche/static/js/filter_data_message.js index 4ecd6d60a..e39134b03 100644 --- a/lemarche/static/js/filter_data_message.js +++ b/lemarche/static/js/filter_data_message.js @@ -1,8 +1,8 @@ function filterData(data, filterText) { return data.filter(item => { - const from = `${item.items[0].From.Name} || ${item.items[0].From.Address}`; - const to = item.items[0].To[0].Address; - const RawHtmlBody = item.items[0].RawHtmlBody; + const from = `${item.From.Name} || ${item.From.Address}`; + const to = item.To[0].Address; + const RawHtmlBody = item.RawHtmlBody; // filter fields return from.includes(filterText) || to.includes(filterText) || RawHtmlBody.includes(filterText); }); @@ -11,14 +11,14 @@ function filterData(data, filterText) { // Fonction pour générer les lignes du tableau HTML function generateTableRows(filteredData) { const rows = filteredData.map(item => { - const sendAt = new Date(item.items[0].SentAtDate).strftime('%d/%m/%Y %Hh%M'); - const from = `${item.items[0].From.Name} - ${item.items[0].From.Address}`; - const RawHtmlBody = item.items[0].RawHtmlBody ? item.items[0].RawHtmlBody : item.items[0].RawTextBody; + const sendAt = new Date(item.SentAtDate).strftime('%d/%m/%Y %Hh%M'); + const from = `${item.From.Name} - ${item.From.Address}`; + const attachementsCount = item.Attachments ? item.Attachments.length : 0; return ` ${sendAt} ${from} - ${RawHtmlBody} + ${attachementsCount} `; }); @@ -35,7 +35,14 @@ function init() { // const filteredData = filterData(rawData, filterText); // generate rows - const tableRows = generateTableRows(rawData); + const headTable = ` + + Date d'envoi + Expéditeur + Nombre de PJ + + `; + const tableRows = headTable + generateTableRows(rawData); // insert rows dataTableBody.innerHTML = tableRows; diff --git a/lemarche/www/conversations/tasks.py b/lemarche/www/conversations/tasks.py index 0688cc74b..9ef747ace 100644 --- a/lemarche/www/conversations/tasks.py +++ b/lemarche/www/conversations/tasks.py @@ -3,6 +3,12 @@ from lemarche.utils.emails import send_mail_async, whitelist_recipient_list +DISCLAIMER_ATTACHMENTS = ( + "\nVeuillez noter que cette conversation email ne prend pas en charge les pièces jointes.\n" + "Pour envoyer un document, un devis ou autre, demandez les coordonnées direct de votre interlocuteur" +) + + def send_first_email_from_conversation(conv: Conversation): siae: Siae = conv.siae from_email = f"{conv.sender_first_name} {conv.sender_last_name} <{conv.sender_email_buyer_encoded}>" @@ -16,7 +22,7 @@ def send_first_email_from_conversation(conv: Conversation): f"{sender_company_name}" f"Ce client vous a contacté via le Marché de l'inclusion. " "Pour échanger avec lui, répondez simplement à cet e-mail.\n" - ) + ) + DISCLAIMER_ATTACHMENTS send_mail_async( email_subject=conv.title, @@ -34,7 +40,7 @@ def send_email_from_conversation( from_email = f"{conv.sender_first_name} {conv.sender_last_name} <{conv.sender_email_buyer_encoded}>" send_mail_async( email_subject=email_subject, - email_body=email_body, + email_body=email_body + DISCLAIMER_ATTACHMENTS, recipient_list=whitelist_recipient_list([conv.sender_email_siae]), from_email=from_email, email_body_html=email_body_html, @@ -45,7 +51,7 @@ def send_email_from_conversation( from_email = f"{siae.contact_full_name} <{conv.sender_email_siae_encoded}>" send_mail_async( email_subject=email_subject, - email_body=email_body, + email_body=email_body + DISCLAIMER_ATTACHMENTS, recipient_list=whitelist_recipient_list([conv.sender_email_buyer]), from_email=from_email, email_body_html=email_body_html,