Explorar o código

remove GenEmail.custom column

Son NK %!s(int64=5) %!d(string=hai) anos
pai
achega
91e38a744b

+ 1 - 1
app/api/views/new_custom_alias.py

@@ -74,7 +74,7 @@ def new_custom_alias():
         LOG.d("full alias already used %s", full_alias)
         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()
 
     if hostname:

+ 1 - 1
app/config.py

@@ -63,7 +63,7 @@ DKIM_SELECTOR = b"dkim"
 with open(DKIM_PRIVATE_KEY_PATH) as f:
     DKIM_PRIVATE_KEY = f.read()
 
-DKIM_HEADERS = [b'from', b'to', b'subject']
+DKIM_HEADERS = [b"from", b"to", b"subject"]
 
 # Database
 DB_URI = os.environ["DB_URI"]

+ 1 - 2
app/dashboard/views/custom_alias.py

@@ -42,7 +42,7 @@ def custom_alias():
                         "create custom alias %s for user %s", full_email, current_user
                     )
                     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()
 
@@ -79,7 +79,6 @@ def custom_alias():
                 gen_email = GenEmail.create(
                     email=full_email,
                     user_id=current_user.id,
-                    custom=True,
                     custom_domain_id=custom_domain.id,
                 )
                 db.session.commit()

+ 2 - 8
app/models.py

@@ -134,10 +134,7 @@ class User(db.Model, ModelMixin, UserMixin):
         if self.is_premium():
             return True
 
-        return (
-            GenEmail.filter_by(user_id=self.id, custom=True).count()
-            < MAX_NB_EMAIL_FREE_PLAN
-        )
+        return GenEmail.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN
 
     def set_password(self, password):
         salt = bcrypt.gensalt()
@@ -389,9 +386,6 @@ class GenEmail(db.Model, ModelMixin):
 
     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(
         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):
                 break
 
-        return GenEmail.create(user_id=user_id, email=email, custom=True)
+        return GenEmail.create(user_id=user_id, email=email)
 
     def __repr__(self):
         return f"<GenEmail {self.id} {self.email}>"

+ 1 - 3
app/oauth/views/authorize.py

@@ -163,9 +163,7 @@ def authorize():
                     flash(f"alias {email} already used", "error")
                     return redirect(request.url)
 
-                gen_email = GenEmail.create(
-                    email=email, user_id=current_user.id, custom=True
-                )
+                gen_email = GenEmail.create(email=email, user_id=current_user.id)
                 db.session.flush()
             else:  # user picks an email from suggestion
                 if chosen_email != current_user.email:

+ 29 - 0
migrations/versions/18e934d58f55_.py

@@ -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 ###

+ 7 - 9
server.py

@@ -38,16 +38,14 @@ from app.models import (
     Subscription,
     PlanEnum,
     ApiKey,
-    CustomDomain)
+    CustomDomain,
+)
 from app.monitor.base import monitor_bp
 from app.oauth.base import oauth_bp
 
 if SENTRY_DSN:
     LOG.d("enable sentry")
-    sentry_sdk.init(
-        dsn=SENTRY_DSN,
-        integrations=[FlaskIntegration()],
-    )
+    sentry_sdk.init(dsn=SENTRY_DSN, integrations=[FlaskIntegration()])
 
 # the app is served behin nginx which uses http and not https
 os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
@@ -122,7 +120,9 @@ def fake_data():
     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="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()
 
     # Create a client
@@ -263,9 +263,7 @@ def jinja2_filter(app):
 
     @app.context_processor
     def inject_stage_and_region():
-        return dict(
-            YEAR=arrow.now().year, URL=URL, SENTRY_DSN=SENTRY_DSN, VERSION=SHA1
-        )
+        return dict(YEAR=arrow.now().year, URL=URL, SENTRY_DSN=SENTRY_DSN, VERSION=SHA1)
 
 
 def setup_paddle_callback(app: Flask):