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 `