rename forward_id to contact_id
This commit is contained in:
parent
578d09c26c
commit
f2d630e597
|
@ -43,7 +43,7 @@ def alias_log(alias_id, page_id):
|
|||
logs = get_alias_log(gen_email, page_id)
|
||||
base = (
|
||||
db.session.query(Contact, ForwardEmailLog)
|
||||
.filter(Contact.id == ForwardEmailLog.forward_id)
|
||||
.filter(Contact.id == ForwardEmailLog.contact_id)
|
||||
.filter(Contact.gen_email_id == gen_email.id)
|
||||
)
|
||||
total = base.count()
|
||||
|
@ -67,7 +67,7 @@ def get_alias_log(gen_email: GenEmail, page_id=0):
|
|||
|
||||
q = (
|
||||
db.session.query(Contact, ForwardEmailLog)
|
||||
.filter(Contact.id == ForwardEmailLog.forward_id)
|
||||
.filter(Contact.id == ForwardEmailLog.contact_id)
|
||||
.filter(Contact.gen_email_id == gen_email.id)
|
||||
.order_by(ForwardEmailLog.id.desc())
|
||||
.limit(PAGE_LIMIT)
|
||||
|
|
|
@ -204,7 +204,7 @@ def get_alias_info(
|
|||
q = (
|
||||
db.session.query(GenEmail, Contact, ForwardEmailLog, Mailbox)
|
||||
.join(Contact, GenEmail.id == Contact.gen_email_id, isouter=True)
|
||||
.join(ForwardEmailLog, Contact.id == ForwardEmailLog.forward_id, isouter=True)
|
||||
.join(ForwardEmailLog, Contact.id == ForwardEmailLog.contact_id, isouter=True)
|
||||
.join(Mailbox, GenEmail.mailbox_id == Mailbox.id, isouter=True)
|
||||
.filter(GenEmail.user_id == user.id)
|
||||
.order_by(GenEmail.created_at.desc())
|
||||
|
|
|
@ -747,14 +747,14 @@ class Contact(db.Model, ModelMixin):
|
|||
def last_reply(self) -> "ForwardEmailLog":
|
||||
"""return the most recent reply"""
|
||||
return (
|
||||
ForwardEmailLog.query.filter_by(forward_id=self.id, is_reply=True)
|
||||
ForwardEmailLog.query.filter_by(contact_id=self.id, is_reply=True)
|
||||
.order_by(desc(ForwardEmailLog.created_at))
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
class ForwardEmailLog(db.Model, ModelMixin):
|
||||
forward_id = db.Column(
|
||||
contact_id = db.Column(
|
||||
db.ForeignKey(Contact.id, ondelete="cascade"), nullable=False
|
||||
)
|
||||
|
||||
|
|
2
cron.py
2
cron.py
|
@ -120,7 +120,7 @@ def stats():
|
|||
|
||||
# nb mails forwarded
|
||||
q = db.session.query(ForwardEmailLog, Contact, GenEmail, User).filter(
|
||||
ForwardEmailLog.forward_id == Contact.id,
|
||||
ForwardEmailLog.contact_id == Contact.id,
|
||||
Contact.gen_email_id == GenEmail.id,
|
||||
GenEmail.user_id == User.id,
|
||||
)
|
||||
|
|
|
@ -314,7 +314,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"], gen_email)
|
||||
forward_log = ForwardEmailLog.create(forward_id=contact.id)
|
||||
forward_log = ForwardEmailLog.create(contact_id=contact.id)
|
||||
|
||||
if gen_email.enabled:
|
||||
# add custom header
|
||||
|
@ -516,17 +516,17 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str:
|
|||
envelope.rcpt_options,
|
||||
)
|
||||
|
||||
ForwardEmailLog.create(forward_id=contact.id, is_reply=True)
|
||||
ForwardEmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
db.session.commit()
|
||||
|
||||
return "250 Message accepted for delivery"
|
||||
|
||||
|
||||
def handle_bounce(alias, envelope, contact, gen_email, msg, smtp, user, mailbox_email):
|
||||
fel: ForwardEmailLog = ForwardEmailLog.create(forward_id=contact.id, bounced=True)
|
||||
fel: ForwardEmailLog = ForwardEmailLog.create(contact_id=contact.id, bounced=True)
|
||||
db.session.commit()
|
||||
|
||||
nb_bounced = ForwardEmailLog.filter_by(forward_id=contact.id, bounced=True).count()
|
||||
nb_bounced = ForwardEmailLog.filter_by(contact_id=contact.id, bounced=True).count()
|
||||
disable_alias_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||
|
||||
# Store the bounced email
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 14167121af69
|
||||
Revises: 7744c5c16159
|
||||
Create Date: 2020-03-17 11:00:00.400334
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "14167121af69"
|
||||
down_revision = "7744c5c16159"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.alter_column("forward_email_log", "forward_id", new_column_name="contact_id")
|
||||
op.drop_constraint(
|
||||
"forward_email_log_forward_id_fkey", "forward_email_log", type_="foreignkey"
|
||||
)
|
||||
op.create_foreign_key(
|
||||
None, "forward_email_log", "contact", ["contact_id"], ["id"], ondelete="cascade"
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.alter_column("forward_email_log", "contact_id", new_column_name="forward_id")
|
|
@ -136,10 +136,10 @@ def test_alias_activities(flask_client):
|
|||
db.session.commit()
|
||||
|
||||
for _ in range(int(PAGE_LIMIT / 2)):
|
||||
ForwardEmailLog.create(forward_id=contact.id, is_reply=True)
|
||||
ForwardEmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
|
||||
for _ in range(int(PAGE_LIMIT / 2) + 2):
|
||||
ForwardEmailLog.create(forward_id=contact.id, blocked=True)
|
||||
ForwardEmailLog.create(contact_id=contact.id, blocked=True)
|
||||
|
||||
r = flask_client.get(
|
||||
url_for("api.get_alias_activities", alias_id=gen_email.id, page_id=0),
|
||||
|
@ -207,7 +207,7 @@ def test_alias_contacts(flask_client):
|
|||
)
|
||||
db.session.commit()
|
||||
|
||||
ForwardEmailLog.create(forward_id=contact.id, is_reply=True)
|
||||
ForwardEmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
db.session.commit()
|
||||
|
||||
r = flask_client.get(
|
||||
|
|
Loading…
Reference in New Issue