remove GenEmail.custom column
This commit is contained in:
parent
d8d0cd9f07
commit
55bccf8f84
|
@ -74,7 +74,7 @@ def new_custom_alias():
|
||||||
LOG.d("full alias already used %s", full_alias)
|
LOG.d("full alias already used %s", full_alias)
|
||||||
return jsonify(error=f"alias {full_alias} already exists"), 409
|
return jsonify(error=f"alias {full_alias} already exists"), 409
|
||||||
|
|
||||||
gen_email = GenEmail.create(user_id=user.id, email=full_alias, custom=True)
|
gen_email = GenEmail.create(user_id=user.id, email=full_alias)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if hostname:
|
if hostname:
|
||||||
|
|
|
@ -63,7 +63,7 @@ DKIM_SELECTOR = b"dkim"
|
||||||
with open(DKIM_PRIVATE_KEY_PATH) as f:
|
with open(DKIM_PRIVATE_KEY_PATH) as f:
|
||||||
DKIM_PRIVATE_KEY = f.read()
|
DKIM_PRIVATE_KEY = f.read()
|
||||||
|
|
||||||
DKIM_HEADERS = [b'from', b'to', b'subject']
|
DKIM_HEADERS = [b"from", b"to", b"subject"]
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
DB_URI = os.environ["DB_URI"]
|
DB_URI = os.environ["DB_URI"]
|
||||||
|
|
|
@ -42,7 +42,7 @@ def custom_alias():
|
||||||
"create custom alias %s for user %s", full_email, current_user
|
"create custom alias %s for user %s", full_email, current_user
|
||||||
)
|
)
|
||||||
gen_email = GenEmail.create(
|
gen_email = GenEmail.create(
|
||||||
email=full_email, user_id=current_user.id, custom=True
|
email=full_email, user_id=current_user.id
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ def custom_alias():
|
||||||
gen_email = GenEmail.create(
|
gen_email = GenEmail.create(
|
||||||
email=full_email,
|
email=full_email,
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
custom=True,
|
|
||||||
custom_domain_id=custom_domain.id,
|
custom_domain_id=custom_domain.id,
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -134,10 +134,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return (
|
return GenEmail.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN
|
||||||
GenEmail.filter_by(user_id=self.id, custom=True).count()
|
|
||||||
< MAX_NB_EMAIL_FREE_PLAN
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
salt = bcrypt.gensalt()
|
salt = bcrypt.gensalt()
|
||||||
|
@ -389,9 +386,6 @@ class GenEmail(db.Model, ModelMixin):
|
||||||
|
|
||||||
enabled = db.Column(db.Boolean(), default=True, nullable=False)
|
enabled = db.Column(db.Boolean(), default=True, nullable=False)
|
||||||
|
|
||||||
# this email has been customized by user, i.e. not generated randomly
|
|
||||||
custom = db.Column(db.Boolean(), default=False, nullable=False, server_default="0")
|
|
||||||
|
|
||||||
custom_domain_id = db.Column(
|
custom_domain_id = db.Column(
|
||||||
db.ForeignKey("custom_domain.id", ondelete="cascade"), nullable=True
|
db.ForeignKey("custom_domain.id", ondelete="cascade"), nullable=True
|
||||||
)
|
)
|
||||||
|
@ -411,7 +405,7 @@ class GenEmail(db.Model, ModelMixin):
|
||||||
if not cls.get_by(email=email):
|
if not cls.get_by(email=email):
|
||||||
break
|
break
|
||||||
|
|
||||||
return GenEmail.create(user_id=user_id, email=email, custom=True)
|
return GenEmail.create(user_id=user_id, email=email)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<GenEmail {self.id} {self.email}>"
|
return f"<GenEmail {self.id} {self.email}>"
|
||||||
|
|
|
@ -163,9 +163,7 @@ def authorize():
|
||||||
flash(f"alias {email} already used", "error")
|
flash(f"alias {email} already used", "error")
|
||||||
return redirect(request.url)
|
return redirect(request.url)
|
||||||
|
|
||||||
gen_email = GenEmail.create(
|
gen_email = GenEmail.create(email=email, user_id=current_user.id)
|
||||||
email=email, user_id=current_user.id, custom=True
|
|
||||||
)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
else: # user picks an email from suggestion
|
else: # user picks an email from suggestion
|
||||||
if chosen_email != current_user.email:
|
if chosen_email != current_user.email:
|
||||||
|
|
29
migrations/versions/18e934d58f55_.py
Normal file
29
migrations/versions/18e934d58f55_.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 18e934d58f55
|
||||||
|
Revises: 0c7f1a48aac9
|
||||||
|
Create Date: 2019-12-22 16:31:33.531138
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy_utils
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '18e934d58f55'
|
||||||
|
down_revision = '0c7f1a48aac9'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('gen_email', 'custom')
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('gen_email', sa.Column('custom', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
|
||||||
|
# ### end Alembic commands ###
|
16
server.py
16
server.py
|
@ -38,16 +38,14 @@ from app.models import (
|
||||||
Subscription,
|
Subscription,
|
||||||
PlanEnum,
|
PlanEnum,
|
||||||
ApiKey,
|
ApiKey,
|
||||||
CustomDomain)
|
CustomDomain,
|
||||||
|
)
|
||||||
from app.monitor.base import monitor_bp
|
from app.monitor.base import monitor_bp
|
||||||
from app.oauth.base import oauth_bp
|
from app.oauth.base import oauth_bp
|
||||||
|
|
||||||
if SENTRY_DSN:
|
if SENTRY_DSN:
|
||||||
LOG.d("enable sentry")
|
LOG.d("enable sentry")
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[FlaskIntegration()])
|
||||||
dsn=SENTRY_DSN,
|
|
||||||
integrations=[FlaskIntegration()],
|
|
||||||
)
|
|
||||||
|
|
||||||
# the app is served behin nginx which uses http and not https
|
# the app is served behin nginx which uses http and not https
|
||||||
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
||||||
|
@ -122,7 +120,9 @@ def fake_data():
|
||||||
GenEmail.create_custom_alias(user.id, "e3@")
|
GenEmail.create_custom_alias(user.id, "e3@")
|
||||||
|
|
||||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||||
CustomDomain.create(user_id=user.id, domain="very-long-domain.com.net.org", verified=True)
|
CustomDomain.create(
|
||||||
|
user_id=user.id, domain="very-long-domain.com.net.org", verified=True
|
||||||
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Create a client
|
# Create a client
|
||||||
|
@ -263,9 +263,7 @@ def jinja2_filter(app):
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_stage_and_region():
|
def inject_stage_and_region():
|
||||||
return dict(
|
return dict(YEAR=arrow.now().year, URL=URL, SENTRY_DSN=SENTRY_DSN, VERSION=SHA1)
|
||||||
YEAR=arrow.now().year, URL=URL, SENTRY_DSN=SENTRY_DSN, VERSION=SHA1
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_paddle_callback(app: Flask):
|
def setup_paddle_callback(app: Flask):
|
||||||
|
|
Loading…
Reference in a new issue