diff --git a/app/dashboard/templates/dashboard/custom_alias.html b/app/dashboard/templates/dashboard/custom_alias.html
index d4bae6fb..984cdd0e 100644
--- a/app/dashboard/templates/dashboard/custom_alias.html
+++ b/app/dashboard/templates/dashboard/custom_alias.html
@@ -48,8 +48,20 @@
-
{% if gen_email.enabled %}
diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py
index f1b5d7f2..6b7cb0d2 100644
--- a/app/dashboard/views/custom_alias.py
+++ b/app/dashboard/views/custom_alias.py
@@ -46,6 +46,7 @@ def custom_alias():
if request.method == "POST":
alias_prefix = request.form.get("prefix")
alias_suffix = request.form.get("suffix")
+ alias_note = request.form.get("note")
if verify_prefix_suffix(
current_user, alias_prefix, alias_suffix, user_custom_domains
@@ -61,7 +62,9 @@ def custom_alias():
"warning",
)
else:
- gen_email = GenEmail.create(user_id=current_user.id, email=full_alias)
+ gen_email = GenEmail.create(
+ user_id=current_user.id, email=full_alias, note=alias_note
+ )
# get the custom_domain_id if alias is created with a custom domain
alias_domain = get_email_domain_part(full_alias)
diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py
index e16a6909..06b1ab98 100644
--- a/app/dashboard/views/index.py
+++ b/app/dashboard/views/index.py
@@ -1,5 +1,6 @@
from flask import render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
+from sqlalchemy import or_
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import joinedload
@@ -124,6 +125,21 @@ def index():
LOG.error("alias %s has been added before to DeletedAlias", email)
db.session.rollback()
+ elif request.form.get("form-name") == "set-note":
+ gen_email_id = request.form.get("gen-email-id")
+ gen_email: GenEmail = GenEmail.get(gen_email_id)
+ note = request.form.get("note")
+
+ gen_email.note = note
+ db.session.commit()
+
+ flash(f"Update note for alias {gen_email.email}", "success")
+ return redirect(
+ url_for(
+ "dashboard.index", highlight_gen_email_id=gen_email.id, query=query
+ )
+ )
+
return redirect(url_for("dashboard.index", query=query))
client_users = (
@@ -164,7 +180,7 @@ def get_alias_info(
)
if query:
- q = q.filter(GenEmail.email.contains(query))
+ q = q.filter(or_(GenEmail.email.contains(query), GenEmail.note.contains(query)))
# pagination activated
if page_id is not None:
diff --git a/app/models.py b/app/models.py
index bc36729e..53efb870 100644
--- a/app/models.py
+++ b/app/models.py
@@ -476,10 +476,12 @@ class GenEmail(db.Model, ModelMixin):
db.ForeignKey("directory.id", ondelete="cascade"), nullable=True
)
+ note = db.Column(db.Text, default=None, nullable=True)
+
user = db.relationship(User)
@classmethod
- def create_new(cls, user_id, prefix):
+ def create_new(cls, user_id, prefix, note=None):
if not prefix:
raise Exception("alias prefix cannot be empty")
@@ -491,7 +493,7 @@ class GenEmail(db.Model, ModelMixin):
if not cls.get_by(email=email):
break
- return GenEmail.create(user_id=user_id, email=email)
+ return GenEmail.create(user_id=user_id, email=email, note=note)
@classmethod
def create_new_random(
diff --git a/migrations/versions/2020_020515_b9f849432543_.py b/migrations/versions/2020_020515_b9f849432543_.py
new file mode 100644
index 00000000..735a7550
--- /dev/null
+++ b/migrations/versions/2020_020515_b9f849432543_.py
@@ -0,0 +1,29 @@
+"""empty message
+
+Revision ID: b9f849432543
+Revises: 9c976df9b9c4
+Create Date: 2020-02-05 15:16:16.912369
+
+"""
+import sqlalchemy_utils
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'b9f849432543'
+down_revision = '9c976df9b9c4'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('gen_email', sa.Column('note', sa.Text(), nullable=True))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('gen_email', 'note')
+ # ### end Alembic commands ###
diff --git a/tests/dashboard/test_custom_alias.py b/tests/dashboard/test_custom_alias.py
new file mode 100644
index 00000000..cb3ad09f
--- /dev/null
+++ b/tests/dashboard/test_custom_alias.py
@@ -0,0 +1,22 @@
+from flask import url_for
+
+from app.config import EMAIL_DOMAIN
+from app.extensions import db
+from app.utils import random_word
+from tests.utils import login
+
+
+def test_add_alias_success(flask_client):
+ login(flask_client)
+ db.session.commit()
+
+ word = random_word()
+
+ r = flask_client.post(
+ url_for("dashboard.custom_alias"),
+ data={"prefix": "prefix", "suffix": f".{word}@{EMAIL_DOMAIN}"},
+ follow_redirects=True,
+ )
+
+ assert r.status_code == 200
+ assert f"Alias prefix.{word}@{EMAIL_DOMAIN} has been created" in str(r.data)