commit
925f6f80bc
|
@ -48,8 +48,20 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row col">
|
||||
<button class="btn btn-primary mt-1">Create</button>
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
<textarea name="note"
|
||||
class="form-control"
|
||||
rows="3"
|
||||
placeholder="Note, can be anything to help you remember WHY you create this alias. This field is optional."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="btn btn-primary mt-1">Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -151,6 +151,28 @@
|
|||
</a>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="row mt-2">
|
||||
|
||||
<div class="col-10">
|
||||
<textarea
|
||||
name="note"
|
||||
class="form-control"
|
||||
rows="2"
|
||||
placeholder="Alias Note.">{{ gen_email.note or "" }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<input type="hidden" name="form-name" value="set-note">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
|
||||
<button class="btn btn-sm btn-outline-success">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{% if gen_email.enabled %}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
29
migrations/versions/2020_020515_b9f849432543_.py
Normal file
29
migrations/versions/2020_020515_b9f849432543_.py
Normal file
|
@ -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 ###
|
22
tests/dashboard/test_custom_alias.py
Normal file
22
tests/dashboard/test_custom_alias.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue