From 45ea72a997560eeb3ae247d8c658869416e84fc3 Mon Sep 17 00:00:00 2001 From: Son NK Date: Fri, 20 Mar 2020 09:55:52 +0100 Subject: [PATCH] make sure to set user_id when creating EmailLog --- email_handler.py | 8 +++++--- tests/api/test_alias.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/email_handler.py b/email_handler.py index d8aaf810..bb997cad 100644 --- a/email_handler.py +++ b/email_handler.py @@ -316,7 +316,7 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str: msg = prepare_pgp_message(msg, mailbox.pgp_finger_print) contact = get_or_create_contact(msg["From"], alias) - forward_log = EmailLog.create(contact_id=contact.id) + forward_log = EmailLog.create(contact_id=contact.id, user_id=contact.user_id) if alias.enabled: # add custom header @@ -517,7 +517,7 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str: envelope.rcpt_options, ) - EmailLog.create(contact_id=contact.id, is_reply=True) + EmailLog.create(contact_id=contact.id, is_reply=True, user_id=contact.user_id) db.session.commit() return "250 Message accepted for delivery" @@ -527,7 +527,9 @@ def handle_bounce( contact: Contact, alias: Alias, msg: Message, user: User, mailbox_email: str ): address = alias.email - fel: EmailLog = EmailLog.create(contact_id=contact.id, bounced=True) + fel: EmailLog = EmailLog.create( + contact_id=contact.id, bounced=True, user_id=contact.user_id + ) db.session.commit() nb_bounced = EmailLog.filter_by(contact_id=contact.id, bounced=True).count() diff --git a/tests/api/test_alias.py b/tests/api/test_alias.py index f83a643c..d5ee3fa2 100644 --- a/tests/api/test_alias.py +++ b/tests/api/test_alias.py @@ -169,10 +169,10 @@ def test_alias_activities(flask_client): db.session.commit() for _ in range(int(PAGE_LIMIT / 2)): - EmailLog.create(contact_id=contact.id, is_reply=True) + EmailLog.create(contact_id=contact.id, is_reply=True, user_id=contact.user_id) for _ in range(int(PAGE_LIMIT / 2) + 2): - EmailLog.create(contact_id=contact.id, blocked=True) + EmailLog.create(contact_id=contact.id, blocked=True, user_id=contact.user_id) r = flask_client.get( url_for("api.get_alias_activities", alias_id=alias.id, page_id=0), @@ -241,7 +241,7 @@ def test_alias_contacts(flask_client): ) db.session.commit() - EmailLog.create(contact_id=contact.id, is_reply=True) + EmailLog.create(contact_id=contact.id, is_reply=True, user_id=contact.user_id) db.session.commit() r = flask_client.get(