Przeglądaj źródła

All users use full-mailbox

- remove can_use_multiple_mailbox col
- remove full_mailbox col
Son NK 5 lat temu
rodzic
commit
aeed62e95b

+ 12 - 16
app/dashboard/templates/dashboard/custom_alias.html

@@ -54,24 +54,20 @@
         </div>
       </div>
 
-      {% if mailboxes|length > 1 or current_user.full_mailbox %}
-        <div class="row mb-2">
-          <div class="col p-1">
-            <select class="form-control custom-select" name="mailbox">
-              {% for mailbox in mailboxes %}
-                <option value="{{ mailbox }}">
-                  {{ mailbox }}
-                </option>
-              {% endfor %}
-            </select>
-            <div class="small-text">
-              The mailbox that owns this alias.
-            </div>
+      <div class="row mb-2">
+        <div class="col p-1">
+          <select class="form-control custom-select" name="mailbox">
+            {% for mailbox in mailboxes %}
+              <option value="{{ mailbox }}">
+                {{ mailbox }}
+              </option>
+            {% endfor %}
+          </select>
+          <div class="small-text">
+            The mailbox that owns this alias.
           </div>
         </div>
-      {% else %}
-        <input type="hidden" name="mailbox" value="{{ mailboxes[0] }}">
-      {% endif %}
+      </div>
 
       <div class="row mb-2">
         <div class="col p-1">

+ 1 - 1
app/dashboard/templates/dashboard/index.html

@@ -151,7 +151,7 @@
             </a>
           </div>
 
-          {% if current_user.full_mailbox and mailboxes|length > 1 %}
+          {% if mailboxes|length > 1 %}
             <form method="post">
               <div class="small-text mt-2">Current mailbox</div>
               <div class="row">

+ 5 - 7
app/dashboard/templates/dashboard/mailbox.html

@@ -22,10 +22,8 @@
         - all emails sent to this alias will be forwarded to this mailbox <br>
         - from this mailbox, you can reply/send emails from the alias. <br><br>
 
-        {% if current_user.full_mailbox %}
-          When you signed up, a mailbox is automatically created with your email <b>{{ current_user.email }}</b>
-          <br><br>
-        {% endif %}
+        When you signed up, a mailbox is automatically created with your email <b>{{ current_user.email }}</b>
+        <br><br>
 
         The mailbox doesn't have to be your email: it can be your friend's email
         if you want to create aliases for your buddy.
@@ -61,7 +59,7 @@
 
           <div class="card-footer p-0">
             <div class="row">
-              {% if mailbox.verified and current_user.full_mailbox %}
+              {% if mailbox.verified %}
                 <div class="col">
                   <form method="post">
                     <input type="hidden" name="form-name" value="set-default">
@@ -70,8 +68,8 @@
                     <button class="card-link btn btn-link
                     {% if mailbox.id == current_user.default_mailbox_id %} disabled {% endif %}"
                     >
-                    Set As Default Mailbox
-                  </button>
+                      Set As Default Mailbox
+                    </button>
                   </form>
                 </div>
               {% endif %}

+ 3 - 4
app/dashboard/views/custom_alias.py

@@ -84,10 +84,9 @@ def custom_alias():
                     gen_email.custom_domain_id = custom_domain.id
 
                 # assign alias to a mailbox
-                if current_user.full_mailbox or mailbox_email != current_user.email:
-                    mailbox = Mailbox.get_by(email=mailbox_email)
-                    gen_email.mailbox_id = mailbox.id
-                    LOG.d("Set alias %s mailbox to %s", full_alias, mailbox)
+                mailbox = Mailbox.get_by(email=mailbox_email)
+                gen_email.mailbox_id = mailbox.id
+                LOG.d("Set alias %s mailbox to %s", full_alias, mailbox)
 
                 db.session.commit()
                 flash(f"Alias {full_alias} has been created", "success")

+ 1 - 8
app/dashboard/views/index.py

@@ -75,14 +75,7 @@ def index():
                     user_id=current_user.id, scheme=scheme
                 )
 
-                if current_user.full_mailbox:
-                    if not current_user.default_mailbox_id:
-                        LOG.error(
-                            "Full mailbox User %s does not have default mailbox ",
-                            current_user,
-                        )
-                    else:
-                        gen_email.mailbox_id = current_user.default_mailbox_id
+                gen_email.mailbox_id = current_user.default_mailbox_id
 
                 db.session.commit()
 

+ 0 - 4
app/dashboard/views/mailbox.py

@@ -27,10 +27,6 @@ class NewMailboxForm(FlaskForm):
 @dashboard_bp.route("/mailbox", methods=["GET", "POST"])
 @login_required
 def mailbox_route():
-    if not current_user.can_use_multiple_mailbox and not current_user.full_mailbox:
-        flash("You don't have access to this page, redirect to home page", "warning")
-        return redirect(url_for("dashboard.index"))
-
     mailboxes = Mailbox.query.filter_by(user_id=current_user.id).all()
 
     new_mailbox_form = NewMailboxForm()

+ 1 - 17
app/models.py

@@ -135,18 +135,6 @@ class User(db.Model, ModelMixin, UserMixin):
         ArrowType, default=lambda: arrow.now().shift(days=7, hours=1), nullable=True
     )
 
-    can_use_multiple_mailbox = db.Column(
-        db.Boolean, default=False, nullable=False, server_default="0"
-    )
-
-    # only use mailbox instead of default to user email
-    # this requires a migration before to:
-    # 1. create default mailbox for the user email address
-    # 2. assign existing aliases to this default mailbox
-    full_mailbox = db.Column(
-        db.Boolean, default=False, nullable=False, server_default="0"
-    )
-
     # the mailbox used when create random alias
     default_mailbox_id = db.Column(
         db.ForeignKey("mailbox.id"), nullable=True, default=None
@@ -169,7 +157,6 @@ class User(db.Model, ModelMixin, UserMixin):
 
         mb = Mailbox.create(user_id=user.id, email=user.email, verified=True)
         db.session.flush()
-        user.full_mailbox = True
         user.default_mailbox_id = mb.id
 
         # Schedule onboarding emails
@@ -296,10 +283,7 @@ class User(db.Model, ModelMixin, UserMixin):
 
     def mailboxes(self) -> [str]:
         """list of mailbox emails that user own"""
-        if self.full_mailbox:
-            mailboxes = []
-        else:
-            mailboxes = [self.email]
+        mailboxes = []
 
         for mailbox in Mailbox.query.filter_by(user_id=self.id, verified=True):
             mailboxes.append(mailbox.email)

+ 31 - 0
migrations/versions/2020_022900_7eef64ffb398_.py

@@ -0,0 +1,31 @@
+"""empty message
+
+Revision ID: 7eef64ffb398
+Revises: 5f191273d067
+Create Date: 2020-02-29 00:02:34.372338
+
+"""
+import sqlalchemy_utils
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '7eef64ffb398'
+down_revision = '5f191273d067'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('users', 'full_mailbox')
+    op.drop_column('users', 'can_use_multiple_mailbox')
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('users', sa.Column('can_use_multiple_mailbox', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
+    op.add_column('users', sa.Column('full_mailbox', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
+    # ### end Alembic commands ###

+ 0 - 2
server.py

@@ -131,8 +131,6 @@ def fake_data():
         activated=True,
         is_admin=True,
         otp_secret="base32secret3232",
-        can_use_multiple_mailbox=True,
-        full_mailbox=True,
     )
     db.session.commit()
 

+ 0 - 20
shell.py

@@ -40,26 +40,6 @@ def send_safari_extension_newsletter():
         )
 
 
-def convert_user_full_mailbox(user):
-    # create a default mailbox
-    default_mb = Mailbox.get_by(user_id=user.id, email=user.email)
-    if not default_mb:
-        LOG.d("create default mailbox for user %s", user)
-        default_mb = Mailbox.create(user_id=user.id, email=user.email, verified=True)
-        db.session.commit()
-
-    # assign existing alias to this mailbox
-    for gen_email in GenEmail.query.filter_by(user_id=user.id):
-        if not gen_email.mailbox_id:
-            LOG.d("Set alias  %s mailbox to default mailbox", gen_email)
-            gen_email.mailbox_id = default_mb.id
-
-    # finally set user to full_mailbox
-    user.full_mailbox = True
-    user.default_mailbox_id = default_mb.id
-    db.session.commit()
-
-
 app = create_app()
 
 with app.app_context():

+ 7 - 9
templates/menu.html

@@ -29,15 +29,13 @@
     </a>
   </li>
 
-  {% if current_user.can_use_multiple_mailbox or current_user.full_mailbox  %}
-    <li class="nav-item">
-      <a href="{{ url_for('dashboard.mailbox_route') }}"
-         class="nav-link {{ 'active' if active_page == 'mailbox' }}">
-        <i class="fe fe-inbox"></i> Mailboxes
-        <span class="badge badge-info" style="font-size: .5rem; top: 5px">Beta</span>
-      </a>
-    </li>
-  {% endif %}
+  <li class="nav-item">
+    <a href="{{ url_for('dashboard.mailbox_route') }}"
+       class="nav-link {{ 'active' if active_page == 'mailbox' }}">
+      <i class="fe fe-inbox"></i> Mailboxes
+      <span class="badge badge-info" style="font-size: .5rem; top: 5px">Beta</span>
+    </a>
+  </li>
 
   <!--
   <li class="nav-item">