mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
rename ForwardEmailLog to EmailLog
This commit is contained in:
parent
087d6c6652
commit
d2c13763a2
9 changed files with 58 additions and 35 deletions
|
@ -12,7 +12,7 @@ from app.dashboard.views.alias_log import get_alias_log
|
|||
from app.dashboard.views.index import get_alias_info, AliasInfo
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import ForwardEmailLog
|
||||
from app.models import EmailLog
|
||||
from app.models import GenEmail, Contact
|
||||
from app.utils import random_string
|
||||
|
||||
|
@ -210,7 +210,7 @@ def serialize_contact(fe: Contact) -> dict:
|
|||
"reverse_alias": fe.website_send_to(),
|
||||
}
|
||||
|
||||
fel: ForwardEmailLog = fe.last_reply()
|
||||
fel: EmailLog = fe.last_reply()
|
||||
if fel:
|
||||
res["last_email_sent_date"] = fel.created_at.format()
|
||||
res["last_email_sent_timestamp"] = fel.created_at.timestamp
|
||||
|
|
|
@ -5,7 +5,7 @@ from flask_login import login_required, current_user
|
|||
from app.config import PAGE_LIMIT
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.extensions import db
|
||||
from app.models import GenEmail, ForwardEmailLog, Contact
|
||||
from app.models import GenEmail, EmailLog, Contact
|
||||
|
||||
|
||||
class AliasLog:
|
||||
|
@ -42,18 +42,18 @@ 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.contact_id)
|
||||
db.session.query(Contact, EmailLog)
|
||||
.filter(Contact.id == EmailLog.contact_id)
|
||||
.filter(Contact.gen_email_id == gen_email.id)
|
||||
)
|
||||
total = base.count()
|
||||
email_forwarded = (
|
||||
base.filter(ForwardEmailLog.is_reply == False)
|
||||
.filter(ForwardEmailLog.blocked == False)
|
||||
base.filter(EmailLog.is_reply == False)
|
||||
.filter(EmailLog.blocked == False)
|
||||
.count()
|
||||
)
|
||||
email_replied = base.filter(ForwardEmailLog.is_reply == True).count()
|
||||
email_blocked = base.filter(ForwardEmailLog.blocked == True).count()
|
||||
email_replied = base.filter(EmailLog.is_reply == True).count()
|
||||
email_blocked = base.filter(EmailLog.blocked == True).count()
|
||||
last_page = (
|
||||
len(logs) < PAGE_LIMIT
|
||||
) # lightweight pagination without counting all objects
|
||||
|
@ -66,10 +66,10 @@ def get_alias_log(gen_email: GenEmail, page_id=0):
|
|||
mailbox = gen_email.mailbox_email()
|
||||
|
||||
q = (
|
||||
db.session.query(Contact, ForwardEmailLog)
|
||||
.filter(Contact.id == ForwardEmailLog.contact_id)
|
||||
db.session.query(Contact, EmailLog)
|
||||
.filter(Contact.id == EmailLog.contact_id)
|
||||
.filter(Contact.gen_email_id == gen_email.id)
|
||||
.order_by(ForwardEmailLog.id.desc())
|
||||
.order_by(EmailLog.id.desc())
|
||||
.limit(PAGE_LIMIT)
|
||||
.offset(page_id * PAGE_LIMIT)
|
||||
)
|
||||
|
|
|
@ -13,7 +13,7 @@ from app.models import (
|
|||
GenEmail,
|
||||
ClientUser,
|
||||
Contact,
|
||||
ForwardEmailLog,
|
||||
EmailLog,
|
||||
DeletedAlias,
|
||||
AliasGeneratorEnum,
|
||||
Mailbox,
|
||||
|
@ -202,9 +202,9 @@ def get_alias_info(
|
|||
aliases = {} # dict of alias and AliasInfo
|
||||
|
||||
q = (
|
||||
db.session.query(GenEmail, Contact, ForwardEmailLog, Mailbox)
|
||||
db.session.query(GenEmail, Contact, EmailLog, Mailbox)
|
||||
.join(Contact, GenEmail.id == Contact.gen_email_id, isouter=True)
|
||||
.join(ForwardEmailLog, Contact.id == ForwardEmailLog.contact_id, isouter=True)
|
||||
.join(EmailLog, Contact.id == EmailLog.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())
|
||||
|
|
|
@ -2,7 +2,7 @@ from flask import render_template, request
|
|||
from flask_login import login_required
|
||||
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.models import ForwardEmailLog
|
||||
from app.models import EmailLog
|
||||
|
||||
|
||||
@dashboard_bp.route("/refused_email", methods=["GET", "POST"])
|
||||
|
@ -13,9 +13,7 @@ def refused_email_route():
|
|||
if highlight_fel_id:
|
||||
highlight_fel_id = int(highlight_fel_id)
|
||||
|
||||
fels: [ForwardEmailLog] = ForwardEmailLog.query.filter(
|
||||
ForwardEmailLog.refused_email_id != None
|
||||
).all()
|
||||
fels: [EmailLog] = EmailLog.query.filter(EmailLog.refused_email_id != None).all()
|
||||
|
||||
# make sure the highlighted fel is the first fel
|
||||
highlight_index = None
|
||||
|
|
|
@ -739,16 +739,16 @@ class Contact(db.Model, ModelMixin):
|
|||
# cannot use formataddr here as this field is for email client, not for MTA
|
||||
# return formataddr((self.website_email.replace("@", " at "), self.reply_email))
|
||||
|
||||
def last_reply(self) -> "ForwardEmailLog":
|
||||
def last_reply(self) -> "EmailLog":
|
||||
"""return the most recent reply"""
|
||||
return (
|
||||
ForwardEmailLog.query.filter_by(contact_id=self.id, is_reply=True)
|
||||
.order_by(desc(ForwardEmailLog.created_at))
|
||||
EmailLog.query.filter_by(contact_id=self.id, is_reply=True)
|
||||
.order_by(desc(EmailLog.created_at))
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
class ForwardEmailLog(db.Model, ModelMixin):
|
||||
class EmailLog(db.Model, ModelMixin):
|
||||
contact_id = db.Column(
|
||||
db.ForeignKey(Contact.id, ondelete="cascade"), nullable=False
|
||||
)
|
||||
|
|
6
cron.py
6
cron.py
|
@ -11,7 +11,7 @@ from app.models import (
|
|||
Subscription,
|
||||
User,
|
||||
GenEmail,
|
||||
ForwardEmailLog,
|
||||
EmailLog,
|
||||
Contact,
|
||||
CustomDomain,
|
||||
Client,
|
||||
|
@ -119,8 +119,8 @@ def stats():
|
|||
LOG.d("total number alias %s", nb_gen_email)
|
||||
|
||||
# nb mails forwarded
|
||||
q = db.session.query(ForwardEmailLog, Contact, GenEmail, User).filter(
|
||||
ForwardEmailLog.contact_id == Contact.id,
|
||||
q = db.session.query(EmailLog, Contact, GenEmail, User).filter(
|
||||
EmailLog.contact_id == Contact.id,
|
||||
Contact.gen_email_id == GenEmail.id,
|
||||
GenEmail.user_id == User.id,
|
||||
)
|
||||
|
|
|
@ -71,7 +71,7 @@ from app.log import LOG
|
|||
from app.models import (
|
||||
GenEmail,
|
||||
Contact,
|
||||
ForwardEmailLog,
|
||||
EmailLog,
|
||||
CustomDomain,
|
||||
Directory,
|
||||
User,
|
||||
|
@ -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(contact_id=contact.id)
|
||||
forward_log = EmailLog.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(contact_id=contact.id, is_reply=True)
|
||||
EmailLog.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(contact_id=contact.id, bounced=True)
|
||||
fel: EmailLog = EmailLog.create(contact_id=contact.id, bounced=True)
|
||||
db.session.commit()
|
||||
|
||||
nb_bounced = ForwardEmailLog.filter_by(contact_id=contact.id, bounced=True).count()
|
||||
nb_bounced = EmailLog.filter_by(contact_id=contact.id, bounced=True).count()
|
||||
disable_alias_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||
|
||||
# Store the bounced email
|
||||
|
|
25
migrations/versions/2020_031711_6e061eb84167_.py
Normal file
25
migrations/versions/2020_031711_6e061eb84167_.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 6e061eb84167
|
||||
Revises: 14167121af69
|
||||
Create Date: 2020-03-17 11:08:02.004125
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "6e061eb84167"
|
||||
down_revision = "14167121af69"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.rename_table("forward_email_log", "email_log")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.rename_table("email_log", "forward_email_log")
|
|
@ -4,7 +4,7 @@ from flask import url_for
|
|||
|
||||
from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN, PAGE_LIMIT
|
||||
from app.extensions import db
|
||||
from app.models import User, ApiKey, GenEmail, Contact, ForwardEmailLog
|
||||
from app.models import User, ApiKey, GenEmail, Contact, EmailLog
|
||||
from app.utils import random_word
|
||||
|
||||
|
||||
|
@ -136,10 +136,10 @@ def test_alias_activities(flask_client):
|
|||
db.session.commit()
|
||||
|
||||
for _ in range(int(PAGE_LIMIT / 2)):
|
||||
ForwardEmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
EmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
|
||||
for _ in range(int(PAGE_LIMIT / 2) + 2):
|
||||
ForwardEmailLog.create(contact_id=contact.id, blocked=True)
|
||||
EmailLog.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(contact_id=contact.id, is_reply=True)
|
||||
EmailLog.create(contact_id=contact.id, is_reply=True)
|
||||
db.session.commit()
|
||||
|
||||
r = flask_client.get(
|
||||
|
|
Loading…
Reference in a new issue